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
}
enum StoreError: Error {
public enum StoreError: Error {
case missingService
case missingUserId
case unexpectedCollectionType(name: String)
case apiCallCollectionNotRegistered(type: String)
case collectionNotRegistered(type: String)
@ -101,30 +102,21 @@ public class Store {
}
}
/// Returns the user's UUID
public var currentUserUUID: UUID? {
if let uuidString = self._settingsStorage.item.userId,
let uuid = UUID(uuidString: uuidString) {
return uuid
}
return nil
public var userId: String? {
return self._settingsStorage.item.userId
}
/// Returns a UUID, using the user's if possible
public func mandatoryUserUUID() -> UUID {
if let uuid = self.currentUserUUID {
return uuid
} else {
let uuid = UIDevice.current.identifierForVendor ?? UUID()
self._settingsStorage.update { settings in
settings.userId = uuid.uuidString
}
return uuid
}
}
/// Returns the user's UUID
// public var currentUserUUID: UUID? {
// if let uuidString = self._settingsStorage.item.userId,
// let uuid = UUID(uuidString: uuidString) {
// return uuid
// }
// return nil
// }
/// Returns the username
func userName() -> String? {
public func userName() -> String? {
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
public func disconnect(resetOption: ResetOption? = nil) {
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
func setSingletonNoSync(instance: T) {
defer {

Loading…
Cancel
Save