sync2
Laurent 8 months ago
parent cca9812b86
commit 760a3135ad
  1. 6
      LeStorage/ApiCallCollection.swift
  2. 4
      LeStorage/Services.swift
  3. 5
      LeStorage/Store.swift
  4. 11
      LeStorage/StoreCenter.swift

@ -18,6 +18,9 @@ protocol SomeCallCollection {
func reset() async
func resumeApiCalls() async
func type() async -> any Storable.Type
func resourceName() async -> String
}
enum ApiCallError: Error, LocalizedError {
@ -371,4 +374,7 @@ actor ApiCallCollection<T: SyncedStorable>: SomeCallCollection {
return self.items
}
func type() async -> any Storable.Type { return T.self }
func resourceName() async -> String { return T.resourceName() }
}

@ -416,7 +416,7 @@ public class Services {
/// - apiCall: An ApiCall instance to configure the returned request
fileprivate func _syncPostRequest<T: SyncedStorable>(from apiCalls: [ApiCall<T>]) throws -> URLRequest {
let urlString = baseURL + "data/"
let urlString = "\(baseURL)\(GetSyncData.resourceName())/"
guard let url = URL(string: urlString) else {
throw ServiceError.urlCreationError(url: urlString)
@ -464,7 +464,7 @@ public class Services {
let encodedDate =
formattedDate.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""
let encodedDateWithPlus = encodedDate.replacingOccurrences(of: "+", with: "%2B")
let urlString = baseURL + "data/?last_update=\(encodedDateWithPlus)"
let urlString = baseURL + "\(GetSyncData.resourceName())/?last_update=\(encodedDateWithPlus)"
Logger.log("urlString = \(urlString)")
guard let url = URL(string: urlString) else {

@ -191,11 +191,6 @@ final public class Store {
}
}
/// Returns the names of all collections
public func collectionNames() -> [(String, any Storable.Type)] {
return self._collections.values.map { ($0.resourceName, $0.type) }
}
// MARK: - Synchronization
/// Calls addOrUpdateIfNewer from the collection corresponding to the instance

@ -446,6 +446,17 @@ public class StoreCenter {
await self._store(id: storeId).loadCollectionItems(results)
}
/// Returns the names of all collections
public func apiCollectionDescriptors() async -> [(String, any Storable.Type)] {
var descriptors: [(String, any Storable.Type)] = []
for collection in self._apiCallCollections.values {
let name = await collection.resourceName()
let type = await collection.type()
descriptors.append((name, type))
}
return descriptors
}
// MARK: - Synchronization
/// Creates the ApiCallCollection to manage the calls to the API

Loading…
Cancel
Save