Skip to content

Commit 5c7de5f

Browse files
authored
Bodega Sample App : Part 1 (#90)
* Updated access levels * Added sort options * Test updates * Added sorting in Search
1 parent af5d9a0 commit 5c7de5f

20 files changed

+101
-87
lines changed

AutocompleteClient/Constants/Constants.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ struct Constants {
8080
static let groupFilter = "filters[group_id]"
8181
static let facetFilterKey = { (key: String) -> String in "filters[\(key)]" }
8282
static let section = "section"
83+
static let sortBy = "sort_by"
84+
static let sortOrder = "sort_order"
8385
static let defaultSectionName = "Products"
8486
}
8587

AutocompleteClient/FW/Logic/Query/SearchFilters.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ public typealias Filter = (key: String, value: String)
1313
public struct SearchFilters {
1414
public let groupFilter: String?
1515
public let facetFilters: [Filter]?
16+
17+
public init(groupFilter: String?, facetFilters: [Filter]?){
18+
self.groupFilter = groupFilter
19+
self.facetFilters = facetFilters
20+
}
1621
}

AutocompleteClient/FW/Logic/Request/Builder/RequestBuilder+QueryItems.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ extension RequestBuilder {
106106
queryItems.add(URLQueryItem(name: Constants.SearchQuery.facetFilterKey(filter.key), value: filter.value))
107107
}
108108

109+
func set(sortOption: SortOption?) {
110+
guard let option = sortOption else { return }
111+
queryItems.add(URLQueryItem(name: Constants.SearchQuery.sortBy, value: option.sortBy))
112+
queryItems.add(URLQueryItem(name: Constants.SearchQuery.sortOrder, value: option.sortOrder.rawValue))
113+
}
114+
109115
func set(_ value: String, forKey key: String) {
110116
queryItems.add(URLQueryItem(name: key, value: value))
111117
}

AutocompleteClient/FW/Logic/Request/CIOAutocompleteQuery.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,30 @@ public struct CIOAutocompleteQuery: CIORequestData {
3636
// TODO: Move to a separate file
3737
public struct CIOSearchQuery: CIORequestData {
3838

39-
let query: String
40-
let filters: SearchFilters?
41-
let page: Int
42-
let section: String
39+
public let query: String
40+
public let page: Int
41+
public let section: String
42+
public let filters: SearchFilters?
43+
public let sortOption: SortOption?
4344

4445
func url(with baseURL: String) -> String {
4546
return String(format: Constants.Query.queryStringFormat, baseURL,
4647
Constants.SearchQuery.pathString, query)
4748
}
4849

49-
public init(query: String, filters: SearchFilters? = nil, page: Int = 1, section: String? = nil) {
50+
public init(query: String, filters: SearchFilters? = nil, sortOption: SortOption? = nil, page: Int = 1, section: String? = nil) {
5051
self.query = query.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)!
5152
self.filters = filters
5253
self.page = page
5354
self.section = section != nil ? section! : Constants.SearchQuery.defaultSectionName
55+
self.sortOption = sortOption
5456
}
5557

5658
func decorateRequest(requestBuilder: RequestBuilder) {
5759
requestBuilder.set(page: self.page)
5860
requestBuilder.set(groupFilter: self.filters?.groupFilter)
5961
requestBuilder.set(facetFilters: self.filters?.facetFilters)
6062
requestBuilder.set(searchSection: self.section)
63+
requestBuilder.set(sortOption: self.sortOption)
6164
}
6265
}

AutocompleteClient/FW/Logic/Result/Search/CIOSearchResponse.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@ import Foundation
1212
Struct representing the search data response from the server.
1313
*/
1414
public struct CIOSearchResponse {
15-
let facets: [Facet]
16-
let results: [SearchResult]
17-
let groups: [CIOGroup]
18-
let redirectInfo: SearchRedirectInfo?
19-
let sortOptions: [SortOption]
20-
let resultCount: Int
21-
let resultID: String
15+
public let facets: [Facet]
16+
public let results: [SearchResult]
17+
public let groups: [CIOGroup]
18+
public let redirectInfo: SearchRedirectInfo?
19+
public let sortOptions: [SortOption]
20+
public let resultCount: Int
21+
public let resultID: String
2222

23-
var isRedirect: Bool {
24-
get {
25-
return self.redirectInfo != nil
26-
}
23+
public var isRedirect: Bool {
24+
return self.redirectInfo != nil
2725
}
2826
}

AutocompleteClient/FW/Logic/Result/Search/Facet.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
import Foundation
1010

11-
struct Facet {
12-
let name: String
13-
let displayName: String
14-
let options: [FacetOption]
15-
let type: String
11+
public struct Facet {
12+
public let name: String
13+
public let displayName: String
14+
public let options: [FacetOption]
15+
public let type: String
1616
}
1717

18-
extension Facet {
18+
public extension Facet {
1919
init?(json: JSONObject) {
2020
guard let name = json["name"] as? String else {
2121
return nil

AutocompleteClient/FW/Logic/Result/Search/FacetOption.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
import Foundation
1010

11-
struct FacetOption {
12-
let count: Int
13-
let displayName: String
14-
let status: String
15-
let value: String
16-
let data: [String: Any]
11+
public struct FacetOption {
12+
public let count: Int
13+
public let displayName: String
14+
public let status: String
15+
public let value: String
16+
public let data: [String: Any]
1717
}
1818

19-
extension FacetOption {
19+
public extension FacetOption {
2020
init?(json: JSONObject) {
2121
guard let count = json["count"] as? Int else { return nil }
2222
guard let value = json["value"] as? String else { return nil }

AutocompleteClient/FW/Logic/Result/Search/SearchRedirectInfo.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
import Foundation
1010

11-
struct SearchRedirectInfo {
12-
let url: String
13-
let matchID: Int
14-
let ruleID: Int
11+
public struct SearchRedirectInfo {
12+
public let url: String
13+
public let matchID: Int
14+
public let ruleID: Int
1515
}
1616

17-
extension SearchRedirectInfo {
17+
public extension SearchRedirectInfo {
1818
init?(object: JSONObject?) {
1919
guard let json = object else { return nil }
2020
guard let data = json["data"] as? JSONObject else { return nil }

AutocompleteClient/FW/Logic/Result/Search/SearchResult.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
import Foundation
1010

11-
struct SearchResult {
12-
let value: String
13-
let data: SearchResultData
14-
let matchedTerms: [String]
15-
let variations: [SearchVariation]
11+
public struct SearchResult {
12+
public let value: String
13+
public let data: SearchResultData
14+
public let matchedTerms: [String]
15+
public let variations: [SearchVariation]
1616
}

AutocompleteClient/FW/Logic/Result/Search/SearchResultData.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88

99
import Foundation
1010

11-
struct SearchResultData {
12-
let id: String
13-
let url: String?
14-
let quantity: String?
15-
let imageURL: String?
16-
let metadata: [String: Any]
17-
let facets: [SearchResultFacet]?
18-
let groups: [CIOGroup]?
11+
public struct SearchResultData {
12+
public let id: String
13+
public let url: String?
14+
public let quantity: String?
15+
public let imageURL: String?
16+
public let metadata: [String: Any]
17+
public let facets: [SearchResultFacet]?
18+
public let groups: [CIOGroup]?
1919
}
2020

21-
extension SearchResultData {
21+
public extension SearchResultData {
2222
init?(json: JSONObject) {
2323
guard let id = json["id"] as? String else { return nil }
2424
self.id = id

0 commit comments

Comments
 (0)