|
|
|
|
@ -41,7 +41,7 @@ public class StoreCenter { |
|
|
|
|
fileprivate var _blackListedUserName: [String] = [] |
|
|
|
|
|
|
|
|
|
init() { |
|
|
|
|
self._loadExistingApiCollections() |
|
|
|
|
// self._loadExistingApiCollections() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Returns the service instance |
|
|
|
|
@ -77,12 +77,6 @@ public class StoreCenter { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _loadExistingApiCollections() { |
|
|
|
|
let string = "clubs" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// MARK: - Settings |
|
|
|
|
|
|
|
|
|
/// Stores the user UUID |
|
|
|
|
@ -117,26 +111,13 @@ public class StoreCenter { |
|
|
|
|
/// Disconnect the user from the storage and resets collection |
|
|
|
|
public func disconnect() { |
|
|
|
|
try? self.service().deleteToken() |
|
|
|
|
|
|
|
|
|
self.resetApiCalls() |
|
|
|
|
self._settingsStorage.update { settings in |
|
|
|
|
settings.username = nil |
|
|
|
|
settings.userId = nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// switch resetOption { |
|
|
|
|
// case .all: |
|
|
|
|
// for collection in self._collections.values { |
|
|
|
|
// collection.reset() |
|
|
|
|
// } |
|
|
|
|
// case .synchronizedOnly: |
|
|
|
|
// for collection in self._collections.values { |
|
|
|
|
// if collection.synchronized { |
|
|
|
|
// collection.reset() |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
// default: |
|
|
|
|
// break |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Returns whether the system has a user token |
|
|
|
|
@ -149,16 +130,28 @@ public class StoreCenter { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Returns or create the ApiCall collection matching the provided T type |
|
|
|
|
func getOrCreateApiCallCollection<T: Storable>() -> ApiCallCollection<T> { |
|
|
|
|
if let apiCallCollection = self._apiCallCollections[T.resourceName()] as? ApiCallCollection<T> { |
|
|
|
|
return apiCallCollection |
|
|
|
|
} |
|
|
|
|
func loadApiCallCollection<T: Storable>(type: T.Type) { |
|
|
|
|
let apiCallCollection = ApiCallCollection<T>() |
|
|
|
|
self._apiCallCollections[T.resourceName()] = apiCallCollection |
|
|
|
|
return apiCallCollection |
|
|
|
|
Task { |
|
|
|
|
do { |
|
|
|
|
try await apiCallCollection.loadFromFile() |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Returns or create the ApiCall collection matching the provided T type |
|
|
|
|
// func getOrCreateApiCallCollection<T: Storable>() -> ApiCallCollection<T> { |
|
|
|
|
// if let apiCallCollection = self._apiCallCollections[T.resourceName()] as? ApiCallCollection<T> { |
|
|
|
|
// return apiCallCollection |
|
|
|
|
// } |
|
|
|
|
// let apiCallCollection = ApiCallCollection<T>() |
|
|
|
|
// self._apiCallCollections[T.resourceName()] = apiCallCollection |
|
|
|
|
// return apiCallCollection |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
/// Returns the ApiCall collection using the resource name of the provided T type |
|
|
|
|
func apiCallCollection<T: Storable>() throws -> ApiCallCollection<T> { |
|
|
|
|
if let collection = self._apiCallCollections[T.resourceName()] as? ApiCallCollection<T> { |
|
|
|
|
@ -350,6 +343,8 @@ public class StoreCenter { |
|
|
|
|
public func destroyStore(identifier: String) { |
|
|
|
|
let directory = "\(Store.storageDirectory)/\(identifier)" |
|
|
|
|
FileManager.default.deleteDirectoryInDocuments(directoryName: directory) |
|
|
|
|
|
|
|
|
|
self._stores.removeValue(forKey: identifier) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Returns whether the collection can synchronize |
|
|
|
|
|