changes for the current user id + minor stuff

multistore
Laurent 1 year ago
parent 69b6fc688d
commit 0d74edd520
  1. 38
      LeStorage/Store.swift
  2. 7
      LeStorage/StoredCollection.swift

@ -13,8 +13,9 @@ public enum ResetOption {
case synchronizedOnly case synchronizedOnly
} }
enum StoreError: Error { public enum StoreError: Error {
case missingService case missingService
case missingUserId
case unexpectedCollectionType(name: String) case unexpectedCollectionType(name: String)
case apiCallCollectionNotRegistered(type: String) case apiCallCollectionNotRegistered(type: String)
case collectionNotRegistered(type: String) case collectionNotRegistered(type: String)
@ -101,30 +102,21 @@ public class Store {
} }
} }
/// Returns the user's UUID public var userId: String? {
public var currentUserUUID: UUID? { return self._settingsStorage.item.userId
if let uuidString = self._settingsStorage.item.userId,
let uuid = UUID(uuidString: uuidString) {
return uuid
}
return nil
} }
/// Returns a UUID, using the user's if possible /// Returns the user's UUID
public func mandatoryUserUUID() -> UUID { // public var currentUserUUID: UUID? {
if let uuid = self.currentUserUUID { // if let uuidString = self._settingsStorage.item.userId,
return uuid // let uuid = UUID(uuidString: uuidString) {
} else { // return uuid
let uuid = UIDevice.current.identifierForVendor ?? UUID() // }
self._settingsStorage.update { settings in // return nil
settings.userId = uuid.uuidString // }
}
return uuid
}
}
/// Returns the username /// Returns the username
func userName() -> String? { public func userName() -> String? {
return self._settingsStorage.item.username return self._settingsStorage.item.username
} }
@ -135,6 +127,10 @@ public class Store {
} }
} }
public func token() -> String? {
return try? self.service().keychainStore.getToken()
}
/// Disconnect the user from the storage and resets collection /// Disconnect the user from the storage and resets collection
public func disconnect(resetOption: ResetOption? = nil) { public func disconnect(resetOption: ResetOption? = nil) {
try? self.service().disconnect() try? self.service().disconnect()

@ -219,6 +219,13 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti
} }
public func writeChangeAndInsertOnServer(instance: T) throws {
defer {
self._hasChanged = true
}
try self._sendInsertionIfNecessary(instance)
}
/// A method the treat the collection as a single instance holder /// A method the treat the collection as a single instance holder
func setSingletonNoSync(instance: T) { func setSingletonNoSync(instance: T) {
defer { defer {

Loading…
Cancel
Save