From 760a3135ad4df516f0293523fe8f62f06423b837 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 17 Mar 2025 11:08:45 +0100 Subject: [PATCH] fix bugs --- LeStorage/ApiCallCollection.swift | 6 ++++++ LeStorage/Services.swift | 4 ++-- LeStorage/Store.swift | 5 ----- LeStorage/StoreCenter.swift | 11 +++++++++++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/LeStorage/ApiCallCollection.swift b/LeStorage/ApiCallCollection.swift index 3190b6a..79806dd 100644 --- a/LeStorage/ApiCallCollection.swift +++ b/LeStorage/ApiCallCollection.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: SomeCallCollection { return self.items } + func type() async -> any Storable.Type { return T.self } + func resourceName() async -> String { return T.resourceName() } + } diff --git a/LeStorage/Services.swift b/LeStorage/Services.swift index 23f18c8..c79b541 100644 --- a/LeStorage/Services.swift +++ b/LeStorage/Services.swift @@ -416,7 +416,7 @@ public class Services { /// - apiCall: An ApiCall instance to configure the returned request fileprivate func _syncPostRequest(from apiCalls: [ApiCall]) 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 { diff --git a/LeStorage/Store.swift b/LeStorage/Store.swift index 0a46a48..c825e35 100644 --- a/LeStorage/Store.swift +++ b/LeStorage/Store.swift @@ -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 diff --git a/LeStorage/StoreCenter.swift b/LeStorage/StoreCenter.swift index 95d1b2e..76384f7 100644 --- a/LeStorage/StoreCenter.swift +++ b/LeStorage/StoreCenter.swift @@ -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