diff --git a/LeStorage/Services.swift b/LeStorage/Services.swift index 62a8234..ab288e9 100644 --- a/LeStorage/Services.swift +++ b/LeStorage/Services.swift @@ -55,6 +55,15 @@ public class Services { // MARK: - Base + /// Runs a request on the API and returns the appropriate response + /// - Parameters: + /// - path: the path of the service in the api, ie. "create-users/" + /// - method: the HTTP method to call + /// - requiresToken: whether the token must be included in the request + public func run(path: String, method: HTTPMethod, requiresToken: Bool) async throws -> U { + return try await self._runRequest(serviceCall: ServiceCall(path: path, method: method, requiresToken: requiresToken)) + } + /// Runs a request using a configuration object /// - Parameters: /// - serviceConf: A instance of ServiceConf diff --git a/LeStorage/Store.swift b/LeStorage/Store.swift index 6964008..08ae90b 100644 --- a/LeStorage/Store.swift +++ b/LeStorage/Store.swift @@ -21,6 +21,33 @@ public enum StoreError: Error, LocalizedError { case castIssue(type: String) case invalidStoreLookup(from: any Storable.Type, to: any Storable.Type) + public var localizedDescription: String { + switch self { + case .missingService: + return "L'instance des services est nulle" + case .missingUsername: + return "Le nom d'utilisateur est manquant" + case .missingUserId: + return "L'identifiant utilisateur est manquant" + case .missingToken: + return "Aucun token n'est stocké" + case .missingKeychainStore: + return "Aucun magasin de trousseau n'est disponible" + case .collectionNotRegistered(let type): + return "La collection \(type) n'est pas enregistrée" + case .apiCallCollectionNotRegistered(let type): + return "La collection d'appels API n'a pas été enregistrée pour \(type)" + case .synchronizationInactive: + return "La synchronisation n'est pas active sur ce StoreCenter" + case .storeNotRegistered(let id): + return "Le magasin avec l'identifiant \(id) n'est pas enregistré" + case .castIssue(let type): + return "Problème de typage: \(type)" + case .invalidStoreLookup(let from, let to): + return "Mauvaise recherche dans le magasin de \(from) à \(to)" + } + } + public var errorDescription: String? { switch self { case .missingService: diff --git a/LeStorage/StoreCenter.swift b/LeStorage/StoreCenter.swift index b1c7760..ed795aa 100644 --- a/LeStorage/StoreCenter.swift +++ b/LeStorage/StoreCenter.swift @@ -581,7 +581,7 @@ public class StoreCenter { /// Basically asks the server for new content public func synchronizeLastUpdates() async throws { - guard self.isAuthenticated else { + guard self.isAuthenticated, self.useSynchronization else { return } guard !self.synchronizesData else { diff --git a/LeStorage/SyncedCollection.swift b/LeStorage/SyncedCollection.swift index c135ed0..a7e8872 100644 --- a/LeStorage/SyncedCollection.swift +++ b/LeStorage/SyncedCollection.swift @@ -331,7 +331,6 @@ public class SyncedCollection: SomeSyncedCollection, Collect // self.collection.delete(instance: instance) // } - /// Deletes the instance in the collection without synchronization public func deleteNoSync(contentOfs sequence: any RandomAccessCollection) { self.collection.delete(contentOfs: sequence) }