From ec1f6825c080385e9a96e74c3be83040ba3cb4ae Mon Sep 17 00:00:00 2001 From: Laurent Date: Thu, 22 May 2025 14:58:15 +0200 Subject: [PATCH] Adds storeParent to manage substorage directories --- LeStorage/StoredCollection.swift | 5 +++++ LeStorageTests/ApiCallTests.swift | 1 + LeStorageTests/CollectionsTests.swift | 8 +++++--- LeStorageTests/IdentifiableTests.swift | 7 +++++-- LeStorageTests/StoredCollectionTests.swift | 3 ++- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/LeStorage/StoredCollection.swift b/LeStorage/StoredCollection.swift index 12b1080..2cb8dd7 100644 --- a/LeStorage/StoredCollection.swift +++ b/LeStorage/StoredCollection.swift @@ -271,6 +271,11 @@ public class StoredCollection: SomeCollection { self.addItem(instance: instance) } + /// Deletes the instance in the collection and sets the collection as changed to trigger a write + public func delete(instance: T) { + self.delete(instance: instance, actionOption: .cascade) + } + /// Deletes the instance in the collection and sets the collection as changed to trigger a write public func delete(instance: T, actionOption: ActionOption) { defer { diff --git a/LeStorageTests/ApiCallTests.swift b/LeStorageTests/ApiCallTests.swift index 746f3d1..5613a24 100644 --- a/LeStorageTests/ApiCallTests.swift +++ b/LeStorageTests/ApiCallTests.swift @@ -18,6 +18,7 @@ class Thing: SyncedModelObject, SyncedStorable, URLParameterConvertible { static func tokenExemptedMethods() -> [LeStorage.HTTPMethod] { return [] } static func filterByStoreIdentifier() -> Bool { return false } static var copyServerResponse: Bool = false + static func storeParent() -> Bool { return false } var id: String = Store.randomId() var name: String = "" diff --git a/LeStorageTests/CollectionsTests.swift b/LeStorageTests/CollectionsTests.swift index d68b7a8..4a0c4ec 100644 --- a/LeStorageTests/CollectionsTests.swift +++ b/LeStorageTests/CollectionsTests.swift @@ -17,14 +17,15 @@ class Car: ModelObject, Storable { } static func relationships() -> [LeStorage.Relationship] { return [] } - + static func storeParent() -> Bool { return false } + } class Boat: ModelObject, SyncedStorable { var id: String = Store.randomId() var lastUpdate: Date = Date() - var shared: Bool? = false + var sharing: LeStorage.SharingStatus? override required init() { super.init() @@ -33,7 +34,8 @@ class Boat: ModelObject, SyncedStorable { static func tokenExemptedMethods() -> [LeStorage.HTTPMethod] { return [] } static func resourceName() -> String { return "boat" } static var copyServerResponse: Bool = false - + static func storeParent() -> Bool { return false } + var storeId: String? { return nil } func copy(from other: any LeStorage.Storable) { diff --git a/LeStorageTests/IdentifiableTests.swift b/LeStorageTests/IdentifiableTests.swift index 0e6c78a..c5bc8af 100644 --- a/LeStorageTests/IdentifiableTests.swift +++ b/LeStorageTests/IdentifiableTests.swift @@ -12,7 +12,8 @@ class IntObject: ModelObject, Storable { static func resourceName() -> String { "int" } static func tokenExemptedMethods() -> [LeStorage.HTTPMethod] { [] } - + static func storeParent() -> Bool { return false } + var id: Int var name: String @@ -30,9 +31,11 @@ class IntObject: ModelObject, Storable { } class StringObject: ModelObject, Storable { + static func resourceName() -> String { "string" } static func tokenExemptedMethods() -> [LeStorage.HTTPMethod] { [] } - + static func storeParent() -> Bool { return false } + var id: String var name: String diff --git a/LeStorageTests/StoredCollectionTests.swift b/LeStorageTests/StoredCollectionTests.swift index 46cc9da..a754b47 100644 --- a/LeStorageTests/StoredCollectionTests.swift +++ b/LeStorageTests/StoredCollectionTests.swift @@ -136,5 +136,6 @@ class MockStorable: ModelObject, Storable { static func relationships() -> [LeStorage.Relationship] { return [] } - + static func storeParent() -> Bool { return false } + }