fixes for data access

sync2
Laurent 1 year ago
parent 7a21f27550
commit 12587aabdb
  1. 2
      LeStorage/Codables/DataLog.swift
  2. 7
      LeStorage/Services.swift
  3. 9
      LeStorage/StoreCenter.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 }

@ -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 ?? "")")

@ -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 {

Loading…
Cancel
Save