Skip to content

Commit a9b92db

Browse files
authored
[Woo POS][Local Catalog] Store full sync date on site entity (#16115)
2 parents 8eaabf7 + 759559c commit a9b92db

20 files changed

+193
-526
lines changed

Modules/Sources/Fakes/Yosemite.generated.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ extension Yosemite.POSSite {
5858
public static func fake() -> Yosemite.POSSite {
5959
.init(
6060
siteID: .fake(),
61-
lastIncrementalSyncDate: .fake()
61+
lastIncrementalSyncDate: .fake(),
62+
lastFullSyncDate: .fake()
6263
)
6364
}
6465
}

Modules/Sources/Storage/GRDB/Migrations/V001InitialSchema.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct V001InitialSchema {
2020
try db.create(table: "site") { siteTable in
2121
siteTable.primaryKey("id", .integer).notNull()
2222
siteTable.column("lastCatalogIncrementalSyncDate", .datetime)
23+
siteTable.column("lastCatalogFullSyncDate", .datetime)
2324
}
2425
}
2526

Modules/Sources/Storage/GRDB/Model/PersistedSite.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ public struct PersistedSite: Codable {
66
// periphery:ignore - TODO: remove ignore when populating database
77
public let id: Int64
88
// periphery:ignore - TODO: remove ignore when populating database
9-
public let lastCatalogIncrementalSyncDate: Date?
9+
public var lastCatalogIncrementalSyncDate: Date?
10+
// periphery:ignore - TODO: remove ignore when populating database
11+
public var lastCatalogFullSyncDate: Date?
1012

1113
// periphery:ignore - TODO: remove ignore when populating database
12-
public init(id: Int64, lastCatalogIncrementalSyncDate: Date? = nil) {
14+
public init(id: Int64, lastCatalogIncrementalSyncDate: Date? = nil, lastCatalogFullSyncDate: Date? = nil) {
1315
self.id = id
1416
self.lastCatalogIncrementalSyncDate = lastCatalogIncrementalSyncDate
17+
self.lastCatalogFullSyncDate = lastCatalogFullSyncDate
1518
}
1619
}
1720

@@ -21,9 +24,11 @@ extension PersistedSite: FetchableRecord, PersistableRecord {
2124

2225
public enum Columns {
2326
// periphery:ignore - TODO: remove ignore when populating database
24-
static let id = Column(CodingKeys.id)
27+
public static let id = Column(CodingKeys.id)
28+
// periphery:ignore - TODO: remove ignore when populating database
29+
public static let lastCatalogIncrementalSyncDate = Column(CodingKeys.lastCatalogIncrementalSyncDate)
2530
// periphery:ignore - TODO: remove ignore when populating database
26-
static let lastCatalogIncrementalSyncDate = Column(CodingKeys.lastCatalogIncrementalSyncDate)
31+
public static let lastCatalogFullSyncDate = Column(CodingKeys.lastCatalogFullSyncDate)
2732
}
2833
}
2934

@@ -32,5 +37,6 @@ private extension PersistedSite {
3237
enum CodingKeys: String, CodingKey {
3338
case id
3439
case lastCatalogIncrementalSyncDate
40+
case lastCatalogFullSyncDate
3541
}
3642
}

Modules/Sources/Storage/Model/Copiable/Models+Copiable.generated.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ extension Storage.GeneralStoreSettings {
115115
lastSelectedOrderStatus: NullableCopiableProp<String> = .copy,
116116
favoriteProductIDs: CopiableProp<[Int64]> = .copy,
117117
searchTermsByKey: CopiableProp<[String: [String]]> = .copy,
118-
isPOSTabVisible: NullableCopiableProp<Bool> = .copy,
119-
posLastFullSyncDate: NullableCopiableProp<Date> = .copy
118+
isPOSTabVisible: NullableCopiableProp<Bool> = .copy
120119
) -> Storage.GeneralStoreSettings {
121120
let storeID = storeID ?? self.storeID
122121
let isTelemetryAvailable = isTelemetryAvailable ?? self.isTelemetryAvailable
@@ -138,7 +137,6 @@ extension Storage.GeneralStoreSettings {
138137
let favoriteProductIDs = favoriteProductIDs ?? self.favoriteProductIDs
139138
let searchTermsByKey = searchTermsByKey ?? self.searchTermsByKey
140139
let isPOSTabVisible = isPOSTabVisible ?? self.isPOSTabVisible
141-
let posLastFullSyncDate = posLastFullSyncDate ?? self.posLastFullSyncDate
142140

143141
return Storage.GeneralStoreSettings(
144142
storeID: storeID,
@@ -160,8 +158,7 @@ extension Storage.GeneralStoreSettings {
160158
lastSelectedOrderStatus: lastSelectedOrderStatus,
161159
favoriteProductIDs: favoriteProductIDs,
162160
searchTermsByKey: searchTermsByKey,
163-
isPOSTabVisible: isPOSTabVisible,
164-
posLastFullSyncDate: posLastFullSyncDate
161+
isPOSTabVisible: isPOSTabVisible
165162
)
166163
}
167164
}

Modules/Sources/Storage/Model/GeneralStoreSettings.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ public struct GeneralStoreSettings: Codable, Equatable, GeneratedCopiable {
8686
///
8787
public var isPOSTabVisible: Bool?
8888

89-
/// Last time a POS catalog full sync was completed for this store.
90-
///
91-
public var posLastFullSyncDate: Date?
9289

9390
public init(storeID: String? = nil,
9491
isTelemetryAvailable: Bool = false,
@@ -109,8 +106,7 @@ public struct GeneralStoreSettings: Codable, Equatable, GeneratedCopiable {
109106
lastSelectedOrderStatus: String? = nil,
110107
favoriteProductIDs: [Int64] = [],
111108
searchTermsByKey: [String: [String]] = [:],
112-
isPOSTabVisible: Bool? = nil,
113-
posLastFullSyncDate: Date? = nil) {
109+
isPOSTabVisible: Bool? = nil) {
114110
self.storeID = storeID
115111
self.isTelemetryAvailable = isTelemetryAvailable
116112
self.telemetryLastReportedTime = telemetryLastReportedTime
@@ -131,7 +127,6 @@ public struct GeneralStoreSettings: Codable, Equatable, GeneratedCopiable {
131127
self.favoriteProductIDs = favoriteProductIDs
132128
self.searchTermsByKey = searchTermsByKey
133129
self.isPOSTabVisible = isPOSTabVisible
134-
self.posLastFullSyncDate = posLastFullSyncDate
135130
}
136131

137132
public func erasingSelectedTaxRateID() -> GeneralStoreSettings {
@@ -153,8 +148,7 @@ public struct GeneralStoreSettings: Codable, Equatable, GeneratedCopiable {
153148
lastSelectedOrderStatus: lastSelectedOrderStatus,
154149
favoriteProductIDs: favoriteProductIDs,
155150
searchTermsByKey: searchTermsByKey,
156-
isPOSTabVisible: isPOSTabVisible,
157-
posLastFullSyncDate: posLastFullSyncDate)
151+
isPOSTabVisible: isPOSTabVisible)
158152
}
159153
}
160154

@@ -189,7 +183,6 @@ extension GeneralStoreSettings {
189183
self.searchTermsByKey = try container.decodeIfPresent([String: [String]].self, forKey: .searchTermsByKey) ?? [:]
190184

191185
self.isPOSTabVisible = try container.decodeIfPresent(Bool.self, forKey: .isPOSTabVisible)
192-
self.posLastFullSyncDate = try container.decodeIfPresent(Date.self, forKey: .posLastFullSyncDate)
193186

194187
// Decode new properties with `decodeIfPresent` and provide a default value if necessary.
195188
}

Modules/Sources/Yosemite/Model/Copiable/Models+Copiable.generated.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,17 @@ extension Yosemite.POSSimpleProduct {
9696
extension Yosemite.POSSite {
9797
public func copy(
9898
siteID: CopiableProp<Int64> = .copy,
99-
lastIncrementalSyncDate: NullableCopiableProp<Date> = .copy
99+
lastIncrementalSyncDate: NullableCopiableProp<Date> = .copy,
100+
lastFullSyncDate: NullableCopiableProp<Date> = .copy
100101
) -> Yosemite.POSSite {
101102
let siteID = siteID ?? self.siteID
102103
let lastIncrementalSyncDate = lastIncrementalSyncDate ?? self.lastIncrementalSyncDate
104+
let lastFullSyncDate = lastFullSyncDate ?? self.lastFullSyncDate
103105

104106
return Yosemite.POSSite(
105107
siteID: siteID,
106-
lastIncrementalSyncDate: lastIncrementalSyncDate
108+
lastIncrementalSyncDate: lastIncrementalSyncDate,
109+
lastFullSyncDate: lastFullSyncDate
107110
)
108111
}
109112
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1+
// periphery:ignore:all
12
import Foundation
23
import Storage
34

45
extension PersistedSite {
56
init(from posSite: POSSite) {
67
self.init(
78
id: posSite.siteID,
8-
lastCatalogIncrementalSyncDate: posSite.lastIncrementalSyncDate
9+
lastCatalogIncrementalSyncDate: posSite.lastIncrementalSyncDate,
10+
lastCatalogFullSyncDate: posSite.lastFullSyncDate
911
)
1012
}
1113

1214
func toPOSSite() -> POSSite {
1315
POSSite(
1416
siteID: id,
15-
lastIncrementalSyncDate: lastCatalogIncrementalSyncDate
17+
lastIncrementalSyncDate: lastCatalogIncrementalSyncDate,
18+
lastFullSyncDate: lastCatalogFullSyncDate
1619
)
1720
}
1821
}

Modules/Sources/Yosemite/PointOfSale/POSSite.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import Foundation
55
public struct POSSite: Equatable, GeneratedCopiable, GeneratedFakeable {
66
public let siteID: Int64
77
public let lastIncrementalSyncDate: Date?
8+
public let lastFullSyncDate: Date?
89

9-
public init(siteID: Int64, lastIncrementalSyncDate: Date? = nil) {
10+
public init(siteID: Int64, lastIncrementalSyncDate: Date? = nil, lastFullSyncDate: Date? = nil) {
1011
self.siteID = siteID
1112
self.lastIncrementalSyncDate = lastIncrementalSyncDate
13+
self.lastFullSyncDate = lastFullSyncDate
1214
}
1315
}

Modules/Sources/Yosemite/Stores/Helpers/SiteSpecificAppSettingsStoreMethods.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ public protocol SiteSpecificAppSettingsStoreMethodsProtocol {
1111
// Search history methods
1212
func getSearchTerms(for itemType: POSItemType, siteID: Int64) -> [String]
1313
func setSearchTerms(_ terms: [String], for itemType: POSItemType, siteID: Int64)
14-
15-
// POS catalog sync timestamp methods
16-
func getPOSLastFullSyncDate(for siteID: Int64) -> Date?
17-
func setPOSLastFullSyncDate(_ date: Date?, for siteID: Int64)
1814
}
1915

2016
/// Methods for managing site-specific app settings
@@ -102,20 +98,6 @@ extension SiteSpecificAppSettingsStoreMethods {
10298
}
10399
}
104100

105-
// MARK: - POS Catalog Sync Timestamps
106-
extension SiteSpecificAppSettingsStoreMethods {
107-
func getPOSLastFullSyncDate(for siteID: Int64) -> Date? {
108-
let storeSettings = getStoreSettings(for: siteID)
109-
return storeSettings.posLastFullSyncDate
110-
}
111-
112-
func setPOSLastFullSyncDate(_ date: Date?, for siteID: Int64) {
113-
let storeSettings = getStoreSettings(for: siteID)
114-
let updatedSettings = storeSettings.copy(posLastFullSyncDate: date)
115-
setStoreSettings(settings: updatedSettings, for: siteID)
116-
}
117-
}
118-
119101
// MARK: - Constants
120102
private enum Constants {
121103
static let generalStoreSettingsFileName = "general-store-settings.plist"

Modules/Sources/Yosemite/Tools/POS/POSCatalogFullSyncService.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import Foundation
22
import protocol Networking.POSCatalogSyncRemoteProtocol
33
import class Networking.AlamofireNetwork
44
import class Networking.POSCatalogSyncRemote
5-
import CocoaLumberjackSwift
65
import Storage
76

87
// TODO - remove the periphery ignore comment when the catalog is integrated with POS.
@@ -20,6 +19,7 @@ public protocol POSCatalogFullSyncServiceProtocol {
2019
public struct POSCatalog {
2120
public let products: [POSProduct]
2221
public let variations: [POSProductVariation]
22+
public let syncDate: Date
2323
}
2424

2525
// TODO - remove the periphery ignore comment when the service is integrated with POS.
@@ -74,6 +74,7 @@ public final class POSCatalogFullSyncService: POSCatalogFullSyncServiceProtocol
7474

7575
private extension POSCatalogFullSyncService {
7676
func loadCatalog(for siteID: Int64, syncRemote: POSCatalogSyncRemoteProtocol) async throws -> POSCatalog {
77+
let syncStartDate = Date.now
7778
// Loads products and variations in batches in parallel.
7879
async let productsTask = batchedLoader.loadAll(
7980
makeRequest: { pageNumber in
@@ -87,7 +88,7 @@ private extension POSCatalogFullSyncService {
8788
)
8889

8990
let (products, variations) = try await (productsTask, variationsTask)
90-
return POSCatalog(products: products, variations: variations)
91+
return POSCatalog(products: products, variations: variations, syncDate: syncStartDate)
9192
}
9293

9394
}

0 commit comments

Comments
 (0)