diff --git a/LeStorage/Codables/DataLog.swift b/LeStorage/Codables/DataLog.swift index c4797d8..d064252 100644 --- a/LeStorage/Codables/DataLog.swift +++ b/LeStorage/Codables/DataLog.swift @@ -9,7 +9,7 @@ import Foundation class DataLog: ModelObject, Storable { - static func resourceName() -> String { return "modelLogs" } + static func resourceName() -> String { return "data-logs" } static func tokenExemptedMethods() -> [HTTPMethod] { return [] } static func filterByStoreIdentifier() -> Bool { return false } diff --git a/LeStorage/Services.swift b/LeStorage/Services.swift index 3c28118..26a6d18 100644 --- a/LeStorage/Services.swift +++ b/LeStorage/Services.swift @@ -88,6 +88,7 @@ public class Services { ) async throws -> V { let debugURL = request.url?.absoluteString ?? "" // print("Run \(request.httpMethod ?? "") \(debugURL)") + let date = Date() let task: (Data, URLResponse) = try await URLSession.shared.data(for: request) print("\(apiCall.method.rawValue) \(String(describing: T.self)) => \(String(data: task.0, encoding: .utf8) ?? "")") @@ -99,7 +100,7 @@ public class Services { try await StoreCenter.main.deleteApiCallById(type: T.self, id: apiCall.id) if T.self == GetSyncData.self { - StoreCenter.main.synchronizeContent(task.0) + StoreCenter.main.synchronizeContent(task.0, date: date) } default: // error @@ -370,6 +371,8 @@ public class Services { /// - request: The synchronization request fileprivate func _runGetSyncLogRequest(_ request: URLRequest) async throws { let debugURL = request.url?.absoluteString ?? "" + let date = Date() + // print("Run \(request.httpMethod ?? "") \(debugURL)") let task: (Data, URLResponse) = try await URLSession.shared.data(for: request) print("\(request.httpMethod ?? "") \(debugURL) => \(String(data: task.0, encoding: .utf8) ?? "")") @@ -379,7 +382,7 @@ public class Services { print("\(debugURL) ended, status code = \(statusCode)") switch statusCode { case 200..<300: // success - StoreCenter.main.synchronizeContent(task.0) + StoreCenter.main.synchronizeContent(task.0, date: date) default: // error Logger.log( "Failed Run \(request.httpMethod ?? "") \(request.url?.absoluteString ?? "")") diff --git a/LeStorage/StoreCenter.swift b/LeStorage/StoreCenter.swift index 552ed0d..0b3859d 100644 --- a/LeStorage/StoreCenter.swift +++ b/LeStorage/StoreCenter.swift @@ -383,7 +383,7 @@ public class StoreCenter { // try await self._services?.synchronizeLastUpdates(since: lastSync) } - func synchronizeContent(_ data: Data) { + func synchronizeContent(_ data: Data, date: Date) { do { guard @@ -412,11 +412,8 @@ public class StoreCenter { } } - if let dateString: String = json["date"] as? String, - let syncDate = Date.iso8601Formatter.date(from: dateString) { - self._settingsStorage.update { settings in - settings.lastSynchronization = syncDate - } + self._settingsStorage.update { settings in + settings.lastSynchronization = date } } catch {