Skip to content

Commit 26476a9

Browse files
committed
Make code more readable for searchProductsByKeyword
1 parent b9d1b0f commit 26476a9

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

Modules/Sources/Yosemite/Stores/ProductStore.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -231,27 +231,27 @@ private extension ProductStore {
231231
productCategory: ProductCategory?,
232232
excludedProductIDs: [Int64],
233233
onCompletion: @escaping (Result<Bool, Error>) -> Void) {
234+
/// internal helper search method
235+
func searchProductsByKeyword(searchFields: [ProductSearchField]) async throws -> [Product] {
236+
try await remote.searchProducts(for: siteID,
237+
keyword: keyword,
238+
searchFields: searchFields,
239+
pageNumber: pageNumber,
240+
pageSize: pageSize,
241+
stockStatus: stockStatus,
242+
productStatus: productStatus,
243+
productType: productType,
244+
productCategory: productCategory,
245+
excludedProductIDs: excludedProductIDs)
246+
}
234247
Task { @MainActor in
235248
do {
236249
let products: [Product]
237250
switch filter {
238-
case .all, .name:
239-
let searchFields: [ProductSearchField] = {
240-
if filter == .name {
241-
return [.name]
242-
}
243-
return []
244-
}()
245-
products = try await remote.searchProducts(for: siteID,
246-
keyword: keyword,
247-
searchFields: searchFields,
248-
pageNumber: pageNumber,
249-
pageSize: pageSize,
250-
stockStatus: stockStatus,
251-
productStatus: productStatus,
252-
productType: productType,
253-
productCategory: productCategory,
254-
excludedProductIDs: excludedProductIDs)
251+
case .all:
252+
products = try await searchProductsByKeyword(searchFields: [])
253+
case .name:
254+
products = try await searchProductsByKeyword(searchFields: [.name])
255255
case .sku:
256256
products = try await remote.searchProductsBySKU(for: siteID,
257257
keyword: keyword,

0 commit comments

Comments
 (0)