Skip to content

Commit 1e4b3e0

Browse files
Merge pull request #8737 from woocommerce/feat/8715-product-tags-migration
[REST API] Migrate product tags endpoints
2 parents f752e43 + fe4d98a commit 1e4b3e0

14 files changed

+495
-14
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,13 @@
806806
EE57C137297F98DB00BC31E7 /* product-variations-load-all-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = EE57C136297F98DB00BC31E7 /* product-variations-load-all-without-data.json */; };
807807
EE57C138297F9AC900BC31E7 /* ProductVariationsBulkUpdateMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE57C130297F97F900BC31E7 /* ProductVariationsBulkUpdateMapperTests.swift */; };
808808
EE57C13A297F9EBE00BC31E7 /* ProductVariationsBulkCreateMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE57C139297F9EBE00BC31E7 /* ProductVariationsBulkCreateMapperTests.swift */; };
809+
EE57C13C297FBECB00BC31E7 /* product-tags-all-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = EE57C13B297FBECB00BC31E7 /* product-tags-all-without-data.json */; };
810+
EE57C13E297FBEE200BC31E7 /* product-tags-created-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = EE57C13D297FBEE200BC31E7 /* product-tags-created-without-data.json */; };
811+
EE57C140297FBEFB00BC31E7 /* product-tags-deleted-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = EE57C13F297FBEFB00BC31E7 /* product-tags-deleted-without-data.json */; };
812+
EE57C143297FCCA700BC31E7 /* product-shipping-classes-load-all-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = EE57C141297FCCA700BC31E7 /* product-shipping-classes-load-all-without-data.json */; };
813+
EE57C144297FCCA700BC31E7 /* product-shipping-classes-load-one-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = EE57C142297FCCA700BC31E7 /* product-shipping-classes-load-one-without-data.json */; };
814+
EE57C146297FCCD200BC31E7 /* ProductShippingClassListMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE57C145297FCCD200BC31E7 /* ProductShippingClassListMapperTests.swift */; };
815+
EE57C148297FCCE000BC31E7 /* ProductShippingClassMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE57C147297FCCE000BC31E7 /* ProductShippingClassMapperTests.swift */; };
809816
EE62EE61295ACF8D009C965B /* RequestConverterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE62EE60295ACF8D009C965B /* RequestConverterTests.swift */; };
810817
EE62EE63295AD45E009C965B /* String+URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE62EE62295AD45E009C965B /* String+URL.swift */; };
811818
EE62EE65295AD46D009C965B /* String+URLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE62EE64295AD46D009C965B /* String+URLTests.swift */; };
@@ -1670,6 +1677,13 @@
16701677
EE57C133297F985A00BC31E7 /* product-variations-bulk-create-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "product-variations-bulk-create-without-data.json"; sourceTree = "<group>"; };
16711678
EE57C136297F98DB00BC31E7 /* product-variations-load-all-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "product-variations-load-all-without-data.json"; sourceTree = "<group>"; };
16721679
EE57C139297F9EBE00BC31E7 /* ProductVariationsBulkCreateMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductVariationsBulkCreateMapperTests.swift; sourceTree = "<group>"; };
1680+
EE57C13B297FBECB00BC31E7 /* product-tags-all-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "product-tags-all-without-data.json"; sourceTree = "<group>"; };
1681+
EE57C13D297FBEE200BC31E7 /* product-tags-created-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "product-tags-created-without-data.json"; sourceTree = "<group>"; };
1682+
EE57C13F297FBEFB00BC31E7 /* product-tags-deleted-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "product-tags-deleted-without-data.json"; sourceTree = "<group>"; };
1683+
EE57C141297FCCA700BC31E7 /* product-shipping-classes-load-all-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "product-shipping-classes-load-all-without-data.json"; sourceTree = "<group>"; };
1684+
EE57C142297FCCA700BC31E7 /* product-shipping-classes-load-one-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "product-shipping-classes-load-one-without-data.json"; sourceTree = "<group>"; };
1685+
EE57C145297FCCD200BC31E7 /* ProductShippingClassListMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductShippingClassListMapperTests.swift; sourceTree = "<group>"; };
1686+
EE57C147297FCCE000BC31E7 /* ProductShippingClassMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductShippingClassMapperTests.swift; sourceTree = "<group>"; };
16731687
EE62EE60295ACF8D009C965B /* RequestConverterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestConverterTests.swift; sourceTree = "<group>"; };
16741688
EE62EE62295AD45E009C965B /* String+URL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+URL.swift"; sourceTree = "<group>"; };
16751689
EE62EE64295AD46D009C965B /* String+URLTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+URLTests.swift"; sourceTree = "<group>"; };
@@ -2402,6 +2416,8 @@
24022416
4524CD9B242CEFAB00B2F20A /* product-on-sale-with-empty-sale-price.json */,
24032417
025CA2C7238F4FF400B05C81 /* product-shipping-classes-load-all.json */,
24042418
020220E123966CD900290165 /* product-shipping-classes-load-one.json */,
2419+
EE57C141297FCCA700BC31E7 /* product-shipping-classes-load-all-without-data.json */,
2420+
EE57C142297FCCA700BC31E7 /* product-shipping-classes-load-one-without-data.json */,
24052421
457FC68B2382B2FD00B41B02 /* product-update.json */,
24062422
AEA056E3296DBA6E00948D52 /* products-batch-update.json */,
24072423
45152818257A84A60076B03C /* product-attributes-all.json */,
@@ -2434,9 +2450,12 @@
24342450
45D685F923D0C3CF005F87D0 /* product-search-sku.json */,
24352451
EEA6583F2966C05D00112DF0 /* product-search-sku-without-data.json */,
24362452
4599FC5B24A6276F0056157A /* product-tags-all.json */,
2453+
EE57C13B297FBECB00BC31E7 /* product-tags-all-without-data.json */,
24372454
45AF57A824AB42CD0088E2F7 /* product-tags-extra.json */,
24382455
45AB8B0E24AA29DC00B5B36E /* product-tags-created.json */,
2456+
EE57C13D297FBEE200BC31E7 /* product-tags-created-without-data.json */,
24392457
45AB8B1224AA34CB00B5B36E /* product-tags-deleted.json */,
2458+
EE57C13F297FBEFB00BC31E7 /* product-tags-deleted-without-data.json */,
24402459
45AB8B1F24AB3E1F00B5B36E /* product-tags-empty.json */,
24412460
CEC4BF90234E40B5008D9195 /* refund-single.json */,
24422461
CEC4BF92234E7EE0008D9195 /* refunds-all.json */,
@@ -2761,6 +2780,8 @@
27612780
45D685FB23D0C739005F87D0 /* ProductSkuMapperTests.swift */,
27622781
4599FC5924A626B70056157A /* ProductTagListMapperTests.swift */,
27632782
CEC4BF94234E7F34008D9195 /* RefundListMapperTests.swift */,
2783+
EE57C145297FCCD200BC31E7 /* ProductShippingClassListMapperTests.swift */,
2784+
EE57C147297FCCE000BC31E7 /* ProductShippingClassMapperTests.swift */,
27642785
CEC4BF8E234E382F008D9195 /* RefundMapperTests.swift */,
27652786
7412A8ED21B6E335005D182A /* ReportOrderMapperTests.swift */,
27662787
743E84F722172E1F00FAC9D7 /* ShipmentTrackingListMapperTests.swift */,
@@ -3121,7 +3142,9 @@
31213142
DE66C55F2977C67D00DAA978 /* shipping-label-account-settings-without-data.json in Resources */,
31223143
E137619929151C7400FD098F /* error-wp-rest-forbidden.json in Resources */,
31233144
31A451CE27863A2E00FE81AA /* stripe-account-wrong-json.json in Resources */,
3145+
EE57C143297FCCA700BC31E7 /* product-shipping-classes-load-all-without-data.json in Resources */,
31243146
26BD9FCD2965EC3C004E0D15 /* product-variations-bulk-create.json in Resources */,
3147+
EE57C13C297FBECB00BC31E7 /* product-tags-all-without-data.json in Resources */,
31253148
028CB718290223CB00331C09 /* account-username-suggestions.json in Resources */,
31263149
0282DD91233A120A006A5FDB /* products-search-photo.json in Resources */,
31273150
DEC2B093297AA60D003923FB /* category-without-data.json in Resources */,
@@ -3131,6 +3154,7 @@
31313154
743E84FC22174CE100FAC9D7 /* restnoroute_error.json in Resources */,
31323155
CE20179320E3EFA7005B4C18 /* broken-orders.json in Resources */,
31333156
D8FBFF2722D529F2006E3336 /* order-stats-v4-month.json in Resources */,
3157+
EE57C140297FBEFB00BC31E7 /* product-tags-deleted-without-data.json in Resources */,
31343158
02B41A92296BEB3000FE3311 /* load-site-current-plan-success.json in Resources */,
31353159
02EF1672292F0D1900D90AD6 /* load-plan-success.json in Resources */,
31363160
DEA6B1C6296C13FB005AA5E9 /* payment-gateway-list-without-data.json in Resources */,
@@ -3217,6 +3241,7 @@
32173241
B5C6FCD620A3768900A4F8E4 /* order.json in Resources */,
32183242
3158FE7426129D9F00E566B9 /* wcpay-account-rejected-other.json in Resources */,
32193243
CC0786C7267BB10700BA9AC1 /* shipping-label-status-success.json in Resources */,
3244+
EE57C144297FCCA700BC31E7 /* product-shipping-classes-load-one-without-data.json in Resources */,
32203245
028CB71B290224D700331C09 /* create-account-error-username.json in Resources */,
32213246
EEA6583E2966B41E00112DF0 /* products-load-all-without-data.json in Resources */,
32223247
68F48B1328E3E5750045C15B /* wc-analytics-customers.json in Resources */,
@@ -3323,6 +3348,7 @@
33233348
A69FE19D2588D70E0059A96B /* order-with-deleted-refunds.json in Resources */,
33243349
E18152C228F85E0A0011A0EC /* iap-products.json in Resources */,
33253350
02B41A90296BC85800FE3311 /* site-domains.json in Resources */,
3351+
EE57C13E297FBEE200BC31E7 /* product-tags-created-without-data.json in Resources */,
33263352
EEA658462966C67C00112DF0 /* products-ids-only-without-data.json in Resources */,
33273353
DE2095C127966EC800171F1C /* coupon-reports.json in Resources */,
33283354
453305F52459ED2700264E50 /* site-post-update.json in Resources */,
@@ -3886,6 +3912,7 @@
38863912
03DCB7442624AD9B00C8953D /* CouponListMapperTests.swift in Sources */,
38873913
AE2D6623272A8F6E004A2C3A /* TelemetryRemoteTests.swift in Sources */,
38883914
B5C151C0217EE3FB00C7BDC1 /* NoteListMapperTests.swift in Sources */,
3915+
EE57C146297FCCD200BC31E7 /* ProductShippingClassListMapperTests.swift in Sources */,
38893916
026CF622237D7E61009563D4 /* ProductVariationsRemoteTests.swift in Sources */,
38903917
DEC51A99274DDDC9009F3DF4 /* SitePluginMapperTests.swift in Sources */,
38913918
EEFAA581295D78E9003583BE /* AuthenticatedRESTRequestTests.swift in Sources */,
@@ -3955,6 +3982,7 @@
39553982
CC07866526790B1100BA9AC1 /* ShippingLabelPurchaseMapperTests.swift in Sources */,
39563983
74002D6A2118B26100A63C19 /* SiteVisitStatsMapperTests.swift in Sources */,
39573984
743E84FA221742E300FAC9D7 /* ShipmentsRemoteTests.swift in Sources */,
3985+
EE57C148297FCCE000BC31E7 /* ProductShippingClassMapperTests.swift in Sources */,
39583986
03DCB7822627394500C8953D /* CouponMapperTests.swift in Sources */,
39593987
03DCB76C262591C400C8953D /* CouponsRemoteTests.swift in Sources */,
39603988
31A451BD2786344B00FE81AA /* StripeRemoteTests.swift in Sources */,

Networking/Networking/Mapper/ProductShippingClassListMapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ struct ProductShippingClassListMapper: Mapper {
1717
.siteID: siteID
1818
]
1919

20-
return try decoder.decode(ProductShippingClassListEnvelope.self, from: response).data
20+
do {
21+
return try decoder.decode(ProductShippingClassListEnvelope.self, from: response).data
22+
} catch {
23+
return try decoder.decode([ProductShippingClass].self, from: response)
24+
}
2125
}
2226
}
2327

Networking/Networking/Mapper/ProductShippingClassMapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ struct ProductShippingClassMapper: Mapper {
1717
.siteID: siteID
1818
]
1919

20-
return try decoder.decode(ProductShippingClassEnvelope.self, from: response).productShippingClass
20+
do {
21+
return try decoder.decode(ProductShippingClassEnvelope.self, from: response).productShippingClass
22+
} catch {
23+
return try decoder.decode(ProductShippingClass.self, from: response)
24+
}
2125
}
2226
}
2327

Networking/Networking/Mapper/ProductTagListMapper.swift

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ struct ProductTagListMapper: Mapper {
2121

2222
switch responseType {
2323
case .load:
24-
return try decoder.decode(ProductTagListEnvelope.self, from: response).tags
24+
do {
25+
return try decoder.decode(ProductTagListEnvelope.self, from: response).tags
26+
} catch {
27+
return try decoder.decode([ProductTag].self, from: response)
28+
}
2529
case .create:
2630
return try decoder.decode(ProductTagListBatchCreateEnvelope.self, from: response).tags
2731
case .delete:
@@ -59,10 +63,16 @@ private struct ProductTagListBatchCreateEnvelope: Decodable {
5963

6064
init(from decoder: Decoder) throws {
6165
let container = try? decoder.container(keyedBy: CodingKeys.self)
62-
let nestedContainer = try? container?.nestedContainer(keyedBy: CodingKeys.self, forKey: .data)
6366

64-
let productTagsCreated: [ProductTagFromBatchCreation]? = nestedContainer?.failsafeDecodeIfPresent(Array<ProductTagFromBatchCreation>.self,
65-
forKey: .create)
67+
let productTagsCreated: [ProductTagFromBatchCreation]?
68+
do {
69+
let nestedContainer = try container?.nestedContainer(keyedBy: CodingKeys.self, forKey: .data)
70+
productTagsCreated = nestedContainer?.failsafeDecodeIfPresent(Array<ProductTagFromBatchCreation>.self,
71+
forKey: .create)
72+
} catch {
73+
productTagsCreated = container?.failsafeDecodeIfPresent(Array<ProductTagFromBatchCreation>.self,
74+
forKey: .create)
75+
}
6676
tags = productTagsCreated?
6777
.filter { $0.error == nil }
6878
.compactMap { (tagCreated) -> ProductTag? in
@@ -88,9 +98,12 @@ private struct ProductTagListBatchDeleteEnvelope: Decodable {
8898

8999
init(from decoder: Decoder) throws {
90100
let container = try? decoder.container(keyedBy: CodingKeys.self)
91-
let nestedContainer = try? container?.nestedContainer(keyedBy: CodingKeys.self, forKey: .data)
92-
93-
tags = nestedContainer?.failsafeDecodeIfPresent(Array<ProductTag>.self, forKey: .delete) ?? []
101+
do {
102+
let nestedContainer = try container?.nestedContainer(keyedBy: CodingKeys.self, forKey: .data)
103+
tags = nestedContainer?.failsafeDecodeIfPresent(Array<ProductTag>.self, forKey: .delete) ?? []
104+
} catch {
105+
tags = container?.failsafeDecodeIfPresent(Array<ProductTag>.self, forKey: .delete) ?? []
106+
}
94107
}
95108

96109
private enum CodingKeys: String, CodingKey {

Networking/Networking/Remote/ProductShippingClassRemote.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ public class ProductShippingClassRemote: Remote {
2626
]
2727

2828
let path = "\(Path.models)"
29-
let request = JetpackRequest(wooApiVersion: .mark3, method: .get, siteID: siteID, path: path, parameters: parameters)
29+
let request = JetpackRequest(wooApiVersion: .mark3,
30+
method: .get,
31+
siteID: siteID,
32+
path: path,
33+
parameters: parameters,
34+
availableAsRESTRequest: true)
3035
let mapper = ProductShippingClassListMapper(siteID: siteID)
3136
enqueue(request, mapper: mapper, completion: completion)
3237
}
@@ -41,7 +46,12 @@ public class ProductShippingClassRemote: Remote {
4146
///
4247
public func loadOne(for siteID: Int64, remoteID: Int64, completion: @escaping (ProductShippingClass?, Error?) -> Void) {
4348
let path = "\(Path.models)/\(remoteID)"
44-
let request = JetpackRequest(wooApiVersion: .mark3, method: .get, siteID: siteID, path: path, parameters: nil)
49+
let request = JetpackRequest(wooApiVersion: .mark3,
50+
method: .get,
51+
siteID: siteID,
52+
path: path,
53+
parameters: nil,
54+
availableAsRESTRequest: true)
4555
let mapper = ProductShippingClassMapper(siteID: siteID)
4656

4757
enqueue(request, mapper: mapper, completion: completion)

Networking/Networking/Remote/ProductTagsRemote.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ public final class ProductTagsRemote: Remote {
2525
]
2626

2727
let path = Path.tags
28-
let request = JetpackRequest(wooApiVersion: .mark3, method: .get, siteID: siteID, path: path, parameters: parameters)
28+
let request = JetpackRequest(wooApiVersion: .mark3,
29+
method: .get,
30+
siteID: siteID,
31+
path: path,
32+
parameters: parameters,
33+
availableAsRESTRequest: true)
2934
let mapper = ProductTagListMapper(siteID: siteID, responseType: .load)
3035

3136
enqueue(request, mapper: mapper, completion: completion)
@@ -47,7 +52,12 @@ public final class ProductTagsRemote: Remote {
4752
]
4853

4954
let path = Path.tagsBatch
50-
let request = JetpackRequest(wooApiVersion: .mark3, method: .post, siteID: siteID, path: path, parameters: parameters)
55+
let request = JetpackRequest(wooApiVersion: .mark3,
56+
method: .post,
57+
siteID: siteID,
58+
path: path,
59+
parameters: parameters,
60+
availableAsRESTRequest: true)
5161
let mapper = ProductTagListMapper(siteID: siteID, responseType: .create)
5262

5363
enqueue(request, mapper: mapper, completion: completion)
@@ -69,7 +79,12 @@ public final class ProductTagsRemote: Remote {
6979
]
7080

7181
let path = Path.tagsBatch
72-
let request = JetpackRequest(wooApiVersion: .mark3, method: .post, siteID: siteID, path: path, parameters: parameters)
82+
let request = JetpackRequest(wooApiVersion: .mark3,
83+
method: .post,
84+
siteID: siteID,
85+
path: path,
86+
parameters: parameters,
87+
availableAsRESTRequest: true)
7388
let mapper = ProductTagListMapper(siteID: siteID, responseType: .delete)
7489

7590
enqueue(request, mapper: mapper, completion: completion)

0 commit comments

Comments
 (0)