|
|
|
|
@ -190,7 +190,7 @@ actor ApiCallCollection<T: SyncedStorable>: SomeCallCollection { |
|
|
|
|
for batch in batches.values { |
|
|
|
|
do { |
|
|
|
|
if batch.count == 1, let apiCall = batch.first, apiCall.method == .get { |
|
|
|
|
let _: Empty = try await self._executeGetCall(apiCall) |
|
|
|
|
try await self._executeGetCall(apiCall: apiCall) |
|
|
|
|
} else { |
|
|
|
|
let results = try await self._executeApiCalls(batch) |
|
|
|
|
if T.copyServerResponse { |
|
|
|
|
@ -211,6 +211,15 @@ actor ApiCallCollection<T: SyncedStorable>: SomeCallCollection { |
|
|
|
|
// Logger.log("\(T.resourceName()) > isRescheduling = \(self._isRescheduling)") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _executeGetCall(apiCall: ApiCall<T>) async throws { |
|
|
|
|
if T.self == GetSyncData.self { |
|
|
|
|
let _: Empty = try await StoreCenter.main.executeGet(apiCall: apiCall) |
|
|
|
|
} else { |
|
|
|
|
let results: [T] = try await StoreCenter.main.executeGet(apiCall: apiCall) |
|
|
|
|
await StoreCenter.main.itemsRetrieved(results, storeId: apiCall.storeId) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Wait for an exponentionnaly long time depending on the number of attemps |
|
|
|
|
fileprivate func _wait() async { |
|
|
|
|
|
|
|
|
|
@ -282,11 +291,16 @@ actor ApiCallCollection<T: SyncedStorable>: SomeCallCollection { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Sends an insert api call for the provided [instance] |
|
|
|
|
func sendGetRequest(instance: T) async throws where T : URLParameterConvertible { |
|
|
|
|
func sendGetRequest(instance: T? = nil, storeId: String? = nil) async throws { |
|
|
|
|
do { |
|
|
|
|
let apiCall = ApiCall<T>(method: .get, data: nil) |
|
|
|
|
apiCall.urlParameters = instance.queryParameters() |
|
|
|
|
let _: Empty? = try await self._prepareAndSendCall(apiCall) |
|
|
|
|
if let parameteredInstance = instance as? URLParameterConvertible { |
|
|
|
|
apiCall.urlParameters = parameteredInstance.queryParameters() |
|
|
|
|
} |
|
|
|
|
if let storeId { |
|
|
|
|
apiCall.urlParameters = [Services.storeIdURLParameter : storeId] |
|
|
|
|
} |
|
|
|
|
try await self._prepareAndSendGetCall(apiCall) |
|
|
|
|
} catch { |
|
|
|
|
self.rescheduleApiCallsIfNecessary() |
|
|
|
|
Logger.error(error) |
|
|
|
|
@ -312,31 +326,16 @@ actor ApiCallCollection<T: SyncedStorable>: SomeCallCollection { |
|
|
|
|
return try await self._executeApiCalls(apiCalls) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// /// Initiates the process of sending the data with the server |
|
|
|
|
//<<<<<<< HEAD |
|
|
|
|
// fileprivate func _sendServerRequest<V: Decodable>(_ method: HTTPMethod, instance: T? = nil) async throws -> V? { |
|
|
|
|
// if let apiCall = try await self._call(method: method, instance: instance) { |
|
|
|
|
// return try await self._prepareAndSendCall(apiCall) |
|
|
|
|
//======= |
|
|
|
|
// fileprivate func _synchronize<V: Decodable>(_ instance: T, method: HTTPMethod) async throws -> V? { |
|
|
|
|
// if let apiCall = try await self._callForInstance(instance, method: method) { |
|
|
|
|
// return try await self._executeApiCall(apiCall) |
|
|
|
|
//>>>>>>> main |
|
|
|
|
// } else { |
|
|
|
|
// return nil |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
fileprivate func _prepareAndSendCall<V: Decodable>(_ apiCall: ApiCall<T>) async throws -> V? { |
|
|
|
|
fileprivate func _prepareAndSendGetCall(_ apiCall: ApiCall<T>) async throws { |
|
|
|
|
self._prepareCall(apiCall: apiCall) |
|
|
|
|
return try await self._executeGetCall(apiCall) |
|
|
|
|
try await self._executeGetCall(apiCall: apiCall) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Executes an API call |
|
|
|
|
/// For POST requests, potentially copies additional data coming from the server during the insert |
|
|
|
|
fileprivate func _executeGetCall<V: Decodable>(_ apiCall: ApiCall<T>) async throws -> V { |
|
|
|
|
return try await StoreCenter.main.executeGet(apiCall: apiCall) |
|
|
|
|
} |
|
|
|
|
// fileprivate func _executeGetCall<V: Decodable>(_ apiCall: ApiCall<T>) async throws -> V { |
|
|
|
|
// return try await StoreCenter.main.executeGet(apiCall: apiCall) |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
/// Executes an API call |
|
|
|
|
/// For POST requests, potentially copies additional data coming from the server during the insert |
|
|
|
|
|