|
|
|
|
@ -96,7 +96,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) |
|
|
|
|
await StoreCenter.main.synchronizeContent(task.0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
default: // error |
|
|
|
|
@ -395,8 +395,8 @@ public class Services { |
|
|
|
|
/// - since: The date from which updates are retrieved |
|
|
|
|
func synchronizeLastUpdates(since: Date?) async throws { |
|
|
|
|
let request = try self._getSyncLogRequest(since: since) |
|
|
|
|
try await self._runRequest(request) { data in |
|
|
|
|
StoreCenter.main.synchronizeContent(data) |
|
|
|
|
if let data = try await self._runRequest(request) { |
|
|
|
|
await StoreCenter.main.synchronizeContent(data) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -429,7 +429,7 @@ public class Services { |
|
|
|
|
/// Runs the a sync request and forwards the response to the StoreCenter for processing |
|
|
|
|
/// - Parameters: |
|
|
|
|
/// - request: The synchronization request |
|
|
|
|
fileprivate func _runRequest(_ request: URLRequest, _ success: (Data) -> ()) async throws { |
|
|
|
|
fileprivate func _runRequest(_ request: URLRequest) async throws -> Data? { |
|
|
|
|
let debugURL = request.url?.absoluteString ?? "" |
|
|
|
|
|
|
|
|
|
// print("Run \(request.httpMethod ?? "") \(debugURL)") |
|
|
|
|
@ -441,7 +441,8 @@ public class Services { |
|
|
|
|
print("\(debugURL) ended, status code = \(statusCode)") |
|
|
|
|
switch statusCode { |
|
|
|
|
case 200..<300: // success |
|
|
|
|
success(task.0) |
|
|
|
|
return task.0 |
|
|
|
|
// success(task.0) |
|
|
|
|
default: // error |
|
|
|
|
Logger.log( |
|
|
|
|
"Failed Run \(request.httpMethod ?? "") \(request.url?.absoluteString ?? "")") |
|
|
|
|
@ -457,6 +458,7 @@ public class Services { |
|
|
|
|
StoreCenter.main.log(message: message) |
|
|
|
|
Logger.w(message) |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// MARK: - Services |
|
|
|
|
@ -622,8 +624,8 @@ public class Services { |
|
|
|
|
/// Returns the list of DataAccess |
|
|
|
|
public func getUserDataAccess() async throws { |
|
|
|
|
let request = try self._baseRequest(call: getUserDataAccessCall) |
|
|
|
|
try await self._runRequest(request) { data in |
|
|
|
|
StoreCenter.main.userDataAccessRetrieved(data) |
|
|
|
|
if let data = try await self._runRequest(request) { |
|
|
|
|
await StoreCenter.main.userDataAccessRetrieved(data) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|