😑 using search-a-licious API now...
This commit is contained in:
@@ -57,7 +57,7 @@ public actor OpenFoodFactsClient {
|
||||
) async throws -> SearchResponseEnvelope {
|
||||
guard
|
||||
var components = URLComponents(
|
||||
url: config.apiURL.appendingPathComponent("/search"),
|
||||
url: config.searchURL,
|
||||
resolvingAgainstBaseURL: true)
|
||||
else {
|
||||
throw OFFError.invalidURL
|
||||
@@ -76,19 +76,19 @@ public actor OpenFoodFactsClient {
|
||||
for param in parameters {
|
||||
switch param {
|
||||
case .query(let q):
|
||||
queryItems.append(URLQueryItem(name: "search_terms", value: q))
|
||||
case .tag(let tag, let value):
|
||||
// V2 allows dynamic tags like `brands_tags=coca`
|
||||
queryItems.append(
|
||||
URLQueryItem(name: "\(tag.rawValue)_tags", value: value))
|
||||
queryItems.append(URLQueryItem(name: "q", value: q))
|
||||
// case .tag(let tag, let value):
|
||||
// // V2 allows dynamic tags like `brands_tags=coca`
|
||||
// queryItems.append(
|
||||
// URLQueryItem(name: "\(tag.rawValue)_tags", value: value))
|
||||
case .page(let p):
|
||||
queryItems.append(URLQueryItem(name: "page", value: String(p)))
|
||||
case .pageSize(let s):
|
||||
queryItems.append(
|
||||
URLQueryItem(name: "page_size", value: String(s)))
|
||||
case .sort(let s):
|
||||
queryItems.append(
|
||||
URLQueryItem(name: "sort_by", value: s.rawValue))
|
||||
// case .sort(let s):
|
||||
// queryItems.append(
|
||||
// URLQueryItem(name: "sort_by", value: s.rawValue))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,11 +140,11 @@ public struct SearchResponseEnvelope: Sendable, Decodable {
|
||||
public let count: Int
|
||||
public let page: Int
|
||||
public let pageSize: Int
|
||||
public let products: [Product]
|
||||
public let hits: [Product]
|
||||
public let pageCount: Int
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case count, page, products
|
||||
case count, page, hits
|
||||
case pageSize = "page_size"
|
||||
case pageCount = "page_count"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user