Skip to content

Commit 9f9025b

Browse files
authored
Merge pull request #101 from woocommerce/feature/98-order-store
Adds OrderStore + Action for OrderList
2 parents 6e079a3 + d6ffc60 commit 9f9025b

File tree

11 files changed

+895
-4
lines changed

11 files changed

+895
-4
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,11 @@
701701
INFOPLIST_FILE = Networking/Info.plist;
702702
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
703703
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
704-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
704+
LD_RUNPATH_SEARCH_PATHS = (
705+
"$(inherited)",
706+
"@executable_path/Frameworks",
707+
"@loader_path/Frameworks",
708+
);
705709
PRODUCT_BUNDLE_IDENTIFIER = com.automattic.woo.Networking;
706710
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
707711
SKIP_INSTALL = YES;
@@ -726,7 +730,11 @@
726730
INFOPLIST_FILE = Networking/Info.plist;
727731
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
728732
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
729-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
733+
LD_RUNPATH_SEARCH_PATHS = (
734+
"$(inherited)",
735+
"@executable_path/Frameworks",
736+
"@loader_path/Frameworks",
737+
);
730738
PRODUCT_BUNDLE_IDENTIFIER = com.automattic.woo.Networking;
731739
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
732740
SKIP_INSTALL = YES;
@@ -742,7 +750,11 @@
742750
CODE_SIGN_STYLE = Automatic;
743751
DEVELOPMENT_TEAM = PZYM8XX95Q;
744752
INFOPLIST_FILE = NetworkingTests/Info.plist;
745-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
753+
LD_RUNPATH_SEARCH_PATHS = (
754+
"$(inherited)",
755+
"@executable_path/Frameworks",
756+
"@loader_path/Frameworks",
757+
);
746758
PRODUCT_BUNDLE_IDENTIFIER = com.automattic.woo.NetworkingTests;
747759
PRODUCT_NAME = "$(TARGET_NAME)";
748760
SWIFT_VERSION = 4.0;
@@ -757,7 +769,11 @@
757769
CODE_SIGN_STYLE = Automatic;
758770
DEVELOPMENT_TEAM = PZYM8XX95Q;
759771
INFOPLIST_FILE = NetworkingTests/Info.plist;
760-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
772+
LD_RUNPATH_SEARCH_PATHS = (
773+
"$(inherited)",
774+
"@executable_path/Frameworks",
775+
"@loader_path/Frameworks",
776+
);
761777
PRODUCT_BUNDLE_IDENTIFIER = com.automattic.woo.NetworkingTests;
762778
PRODUCT_NAME = "$(TARGET_NAME)";
763779
SWIFT_VERSION = 4.0;

Networking/Networking/Model/Address.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,28 @@ private extension Address {
3232
case country = "country"
3333
}
3434
}
35+
36+
37+
// MARK: - Comparable Conformance
38+
//
39+
extension Address: Comparable {
40+
public static func == (lhs: Address, rhs: Address) -> Bool {
41+
return lhs.firstName == rhs.firstName &&
42+
lhs.lastName == rhs.lastName &&
43+
lhs.company == rhs.company &&
44+
lhs.address1 == rhs.address1 &&
45+
lhs.address2 == rhs.address2 &&
46+
lhs.city == rhs.city &&
47+
lhs.state == rhs.state &&
48+
lhs.postcode == rhs.postcode &&
49+
lhs.country == rhs.country
50+
}
51+
52+
public static func < (lhs: Address, rhs: Address) -> Bool {
53+
return lhs.city < rhs.city ||
54+
(lhs.city == rhs.city && lhs.state < rhs.state) ||
55+
(lhs.city == rhs.city && lhs.state == rhs.state && lhs.postcode < rhs.postcode) ||
56+
(lhs.city == rhs.city && lhs.state == rhs.state && lhs.postcode == rhs.postcode && lhs.lastName < rhs.lastName)
57+
}
58+
}
59+

Networking/Networking/Model/Order.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,35 @@ private extension Order {
6060
case billingAddress = "billing"
6161
}
6262
}
63+
64+
65+
// MARK: - Comparable Conformance
66+
//
67+
extension Order: Comparable {
68+
public static func == (lhs: Order, rhs: Order) -> Bool {
69+
return lhs.orderID == rhs.orderID &&
70+
lhs.parentID == rhs.parentID &&
71+
lhs.customerID == rhs.customerID &&
72+
lhs.number == rhs.number &&
73+
lhs.status == rhs.status &&
74+
lhs.dateCreated == rhs.dateCreated &&
75+
lhs.dateModified == rhs.dateModified &&
76+
lhs.datePaid == rhs.datePaid &&
77+
lhs.discountTotal == rhs.discountTotal &&
78+
lhs.discountTax == rhs.discountTax &&
79+
lhs.shippingTotal == rhs.shippingTotal &&
80+
lhs.shippingTax == rhs.shippingTax &&
81+
lhs.total == rhs.total &&
82+
lhs.totalTax == rhs.totalTax &&
83+
lhs.billingAddress == rhs.billingAddress &&
84+
lhs.shippingAddress == rhs.shippingAddress &&
85+
lhs.items.count == rhs.items.count &&
86+
lhs.items.sorted() == rhs.items.sorted()
87+
}
88+
89+
public static func < (lhs: Order, rhs: Order) -> Bool {
90+
return lhs.orderID < rhs.orderID ||
91+
(lhs.orderID == rhs.orderID && lhs.dateCreated < rhs.dateCreated) ||
92+
(lhs.orderID == rhs.orderID && lhs.dateCreated == rhs.dateCreated && lhs.dateModified < rhs.dateModified)
93+
}
94+
}

Networking/Networking/Model/OrderItem.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,28 @@ private extension OrderItem {
3636
case variationID = "variation_id"
3737
}
3838
}
39+
40+
41+
// MARK: - Comparable Conformance
42+
//
43+
extension OrderItem: Comparable {
44+
public static func == (lhs: OrderItem, rhs: OrderItem) -> Bool {
45+
return lhs.itemID == rhs.itemID &&
46+
lhs.name == rhs.name &&
47+
lhs.productID == rhs.productID &&
48+
lhs.quantity == rhs.quantity &&
49+
lhs.sku == rhs.sku &&
50+
lhs.subtotal == rhs.subtotal &&
51+
lhs.subtotalTax == rhs.subtotalTax &&
52+
lhs.taxClass == rhs.taxClass &&
53+
lhs.total == rhs.total &&
54+
lhs.totalTax == rhs.totalTax &&
55+
lhs.variationID == rhs.variationID
56+
}
57+
58+
public static func < (lhs: OrderItem, rhs: OrderItem) -> Bool {
59+
return lhs.itemID < rhs.itemID ||
60+
(lhs.itemID == rhs.itemID && lhs.productID < rhs.productID) ||
61+
(lhs.itemID == rhs.itemID && lhs.productID == rhs.productID && lhs.name < rhs.name)
62+
}
63+
}

Yosemite/Yosemite.xcodeproj/project.pbxproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
/* Begin PBXBuildFile section */
1010
0E67B79585034C4DD75C8117 /* Pods_Yosemite.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C25501C7F936D2FD32FAF3F4 /* Pods_Yosemite.framework */; };
1111
36941EA7B9242CAB1FF828BC /* Pods_YosemiteTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 991BBCE6E4A92F0A028885D8 /* Pods_YosemiteTests.framework */; };
12+
745D21C220D8043A00BBE7C3 /* generic_error.json in Sources */ = {isa = PBXBuildFile; fileRef = 745D21C120D8043A00BBE7C3 /* generic_error.json */; };
13+
74A7688C20D45EBA00F9D437 /* OrderStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74A7688B20D45EBA00F9D437 /* OrderStore.swift */; };
14+
74A7688E20D45ED400F9D437 /* OrderStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74A7688D20D45ED400F9D437 /* OrderStoreTests.swift */; };
15+
74A7689020D45F9300F9D437 /* OrderAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74A7688F20D45F9300F9D437 /* OrderAction.swift */; };
16+
74A7689220D47F9E00F9D437 /* orders.json in Resources */ = {isa = PBXBuildFile; fileRef = 74A7689120D47F9E00F9D437 /* orders.json */; };
1217
B546CCF22093636A007CDA5F /* Yosemite.h in Headers */ = {isa = PBXBuildFile; fileRef = B546CCF12093636A007CDA5F /* Yosemite.h */; settings = {ATTRIBUTES = (Public, ); }; };
1318
B57A133220D2C787003D88DF /* StorageAccount+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57A133120D2C787003D88DF /* StorageAccount+Extensions.swift */; };
1419
B5A01CA120D19C4700E3207E /* MockupStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A01CA020D19C4700E3207E /* MockupStorage.swift */; };
@@ -42,6 +47,11 @@
4247
/* End PBXContainerItemProxy section */
4348

4449
/* Begin PBXFileReference section */
50+
745D21C120D8043A00BBE7C3 /* generic_error.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = generic_error.json; sourceTree = "<group>"; };
51+
74A7688B20D45EBA00F9D437 /* OrderStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderStore.swift; sourceTree = "<group>"; };
52+
74A7688D20D45ED400F9D437 /* OrderStoreTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderStoreTests.swift; sourceTree = "<group>"; };
53+
74A7688F20D45F9300F9D437 /* OrderAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderAction.swift; sourceTree = "<group>"; };
54+
74A7689120D47F9E00F9D437 /* orders.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = orders.json; sourceTree = "<group>"; };
4555
79402E7AD394EEB60C39A4B8 /* Pods-YosemiteTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-YosemiteTests.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-YosemiteTests/Pods-YosemiteTests.debug.xcconfig"; sourceTree = "<group>"; };
4656
7F47E19203B04CF6BB5EA659 /* Pods-Yosemite.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Yosemite.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-Yosemite/Pods-Yosemite.debug.xcconfig"; sourceTree = "<group>"; };
4757
93D120F57D5D14A10B3AFFFD /* Pods-Yosemite.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Yosemite.release.xcconfig"; path = "../Pods/Target Support Files/Pods-Yosemite/Pods-Yosemite.release.xcconfig"; sourceTree = "<group>"; };
@@ -110,6 +120,7 @@
110120
isa = PBXGroup;
111121
children = (
112122
B5BC736420D1A98500B5B6FA /* AccountStore.swift */,
123+
74A7688B20D45EBA00F9D437 /* OrderStore.swift */,
113124
);
114125
path = Stores;
115126
sourceTree = "<group>";
@@ -118,6 +129,7 @@
118129
isa = PBXGroup;
119130
children = (
120131
B5BC736720D1AA8F00B5B6FA /* AccountStoreTests.swift */,
132+
74A7688D20D45ED400F9D437 /* OrderStoreTests.swift */,
121133
);
122134
path = Stores;
123135
sourceTree = "<group>";
@@ -126,6 +138,8 @@
126138
isa = PBXGroup;
127139
children = (
128140
B5BC736A20D1AAE900B5B6FA /* me.json */,
141+
74A7689120D47F9E00F9D437 /* orders.json */,
142+
745D21C120D8043A00BBE7C3 /* generic_error.json */,
129143
);
130144
path = Resources;
131145
sourceTree = "<group>";
@@ -240,6 +254,7 @@
240254
isa = PBXGroup;
241255
children = (
242256
B5DC3CB020D1B8720063AC41 /* AccountAction.swift */,
257+
74A7688F20D45F9300F9D437 /* OrderAction.swift */,
243258
);
244259
path = Actions;
245260
sourceTree = "<group>";
@@ -356,6 +371,7 @@
356371
isa = PBXResourcesBuildPhase;
357372
buildActionMask = 2147483647;
358373
files = (
374+
74A7689220D47F9E00F9D437 /* orders.json in Resources */,
359375
B5BC736B20D1AAE900B5B6FA /* me.json in Resources */,
360376
);
361377
runOnlyForDeploymentPostprocessing = 0;
@@ -428,6 +444,8 @@
428444
B5DC3CB120D1B8720063AC41 /* AccountAction.swift in Sources */,
429445
B5BC736520D1A98500B5B6FA /* AccountStore.swift in Sources */,
430446
B5B5C797208E49B600642956 /* Action+Internal.swift in Sources */,
447+
74A7688C20D45EBA00F9D437 /* OrderStore.swift in Sources */,
448+
74A7689020D45F9300F9D437 /* OrderAction.swift in Sources */,
431449
B5C9DE182087FF0E006B910A /* Assert.swift in Sources */,
432450
B5C9DE162087FF0E006B910A /* Store.swift in Sources */,
433451
B57A133220D2C787003D88DF /* StorageAccount+Extensions.swift in Sources */,
@@ -438,11 +456,13 @@
438456
isa = PBXSourcesBuildPhase;
439457
buildActionMask = 2147483647;
440458
files = (
459+
74A7688E20D45ED400F9D437 /* OrderStoreTests.swift in Sources */,
441460
B5C9DE272087FF20006B910A /* MockupAcount.swift in Sources */,
442461
B5C9DE222087FF20006B910A /* DispatcherTests.swift in Sources */,
443462
B5A01CA120D19C4700E3207E /* MockupStorage.swift in Sources */,
444463
B5C9DE242087FF20006B910A /* StoreTests.swift in Sources */,
445464
B5C9DE252087FF20006B910A /* MockupProcessor.swift in Sources */,
465+
745D21C220D8043A00BBE7C3 /* generic_error.json in Sources */,
446466
B5C9DE282087FF20006B910A /* MockupSite.swift in Sources */,
447467
B5BC736820D1AA8F00B5B6FA /* AccountStoreTests.swift in Sources */,
448468
B5BC736E20D1AB3600B5B6FA /* Constants.swift in Sources */,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Foundation
2+
import Networking
3+
4+
5+
6+
// MARK: - Public Aliases
7+
//
8+
public typealias Order = Networking.Order
9+
10+
11+
// MARK: - OrderAction: Defines all of the Actions supported by the OrderStore.
12+
//
13+
public enum OrderAction: Action {
14+
case retrieveOrders(siteID: Int, onCompletion: ([Order]?, Error?) -> Void)
15+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import Foundation
2+
import Networking
3+
4+
5+
// MARK: - OrderStore
6+
//
7+
public class OrderStore: Store {
8+
9+
/// Registers for supported Actions.
10+
///
11+
override public func registerSupportedActions(in dispatcher: Dispatcher) {
12+
dispatcher.register(processor: self, for: OrderAction.self)
13+
}
14+
15+
/// Receives and executes Actions.
16+
///
17+
override public func onAction(_ action: Action) {
18+
guard let action = action as? OrderAction else {
19+
assertionFailure("OrderStore received an unsupported action")
20+
return
21+
}
22+
23+
switch action {
24+
case .retrieveOrders(let siteId, let onCompletion):
25+
retrieveOrders(siteId: siteId, onCompletion: onCompletion)
26+
}
27+
}
28+
}
29+
30+
31+
// MARK: - Services!
32+
//
33+
extension OrderStore {
34+
35+
/// Retrieves the orders associated with a given Site ID (if any!).
36+
///
37+
func retrieveOrders(siteId: Int, onCompletion: @escaping ([Order]?, Error?) -> Void) {
38+
let remote = OrdersRemote(network: network)
39+
40+
remote.loadAllOrders(for: siteId) { (orders, error) in
41+
guard let orders = orders else {
42+
onCompletion(nil, error)
43+
return
44+
}
45+
46+
onCompletion(orders, nil)
47+
}
48+
}
49+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"error": "unknown_token",
3+
"message": "Unknown Token"
4+
}

0 commit comments

Comments
 (0)