Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ class ProductClassificationService {
throw new IllegalArgumentException("Invalid facilityId: ${facilityId}")
}

List<String> productClassifications = Product.createCriteria().listDistinct() {
Set<String> productClassifications = Product.createCriteria().listDistinct() {
projections {
groupProperty("abcClass")
}
isNotNull("abcClass")
ne("abcClass", "") // Once classifications have their own entity, this should be removed.
} as List<String>
} as Set<String>

productClassifications += InventoryLevel.createCriteria().listDistinct() {
projections {
Expand All @@ -55,15 +55,12 @@ class ProductClassificationService {
eq("inventory", facility.inventory)
isNotNull("abcClass")
ne("abcClass", "") // Once classifications have their own entity, this should be removed.
} as List<String>

// Sort the results by ABC class name. Once ABC class becomes its own domain, this can be moved to the query.
Collections.sort(productClassifications)
} as Set<String>

// We convert to a DTO here instead of returning the raw string because it will make things easier
// once product classification becomes a proper entity.
return productClassifications.collect {
new ProductClassificationDto(name: it)
}
return productClassifications
.sort() // Once ABC class becomes its own domain, this sort by name can be moved to the query.
.collect{ new ProductClassificationDto(name: it) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ class ProductClassificationApiCRUDSpec extends ApiSpec {

then:
assert classifications.size() >= 3 // Don't use '==' because other tests might have left data in the db
assert asNames(classifications).containsAll([CLASS_A, CLASS_B, CLASS_C])

List<String> names = asNames(classifications)
assert names.containsAll([CLASS_A, CLASS_B, CLASS_C])
assert names.size() == new HashSet<>(names).size() // Ensure there are no duplicates
}

void 'given an invalid facility, list correctly errors'() {
Expand Down