diff --git a/LeStorage/Codables/DataAccess.swift b/LeStorage/Codables/DataAccess.swift index ab428ce..f791c62 100644 --- a/LeStorage/Codables/DataAccess.swift +++ b/LeStorage/Codables/DataAccess.swift @@ -12,6 +12,7 @@ class DataAccess: SyncedModelObject, SyncedStorable { static func tokenExemptedMethods() -> [HTTPMethod] { return [] } static func resourceName() -> String { return "data-access" } static func relationships() -> [Relationship] { return [] } + static var copyServerResponse: Bool = false override required init() { super.init() diff --git a/LeStorage/Codables/FailedAPICall.swift b/LeStorage/Codables/FailedAPICall.swift index 53786dd..6b340bd 100644 --- a/LeStorage/Codables/FailedAPICall.swift +++ b/LeStorage/Codables/FailedAPICall.swift @@ -8,10 +8,11 @@ import Foundation class FailedAPICall: SyncedModelObject, SyncedStorable { - + static func resourceName() -> String { return "failed-api-calls" } static func tokenExemptedMethods() -> [HTTPMethod] { return [] } static func relationships() -> [Relationship] { return [] } + static var copyServerResponse: Bool = false override required init() { self.callId = "" diff --git a/LeStorage/Codables/GetSyncData.swift b/LeStorage/Codables/GetSyncData.swift index 7c8d9e9..bd8882e 100644 --- a/LeStorage/Codables/GetSyncData.swift +++ b/LeStorage/Codables/GetSyncData.swift @@ -20,7 +20,8 @@ class GetSyncData: SyncedModelObject, SyncedStorable, URLParameterConvertible { } static func tokenExemptedMethods() -> [HTTPMethod] { return [] } - + static var copyServerResponse: Bool = false + static func resourceName() -> String { return "sync-data" } diff --git a/LeStorage/Codables/Log.swift b/LeStorage/Codables/Log.swift index 5a223ac..ab9f2a7 100644 --- a/LeStorage/Codables/Log.swift +++ b/LeStorage/Codables/Log.swift @@ -12,6 +12,7 @@ class Log: SyncedModelObject, SyncedStorable { static func resourceName() -> String { return "logs" } static func tokenExemptedMethods() -> [HTTPMethod] { return [] } static func relationships() -> [Relationship] { return [] } + static var copyServerResponse: Bool = false override required init() { super.init() diff --git a/LeStorage/ModelObject.swift b/LeStorage/ModelObject.swift index 99e785f..1c934d5 100644 --- a/LeStorage/ModelObject.swift +++ b/LeStorage/ModelObject.swift @@ -53,10 +53,6 @@ open class SyncedModelObject: BaseModelObject { public var lastUpdate: Date = Date() public var shared: Bool? - open func copyFromServerInstance(_ instance: any Storable) -> Bool { - return false - } - public override init() { super.init() } diff --git a/LeStorage/Services.swift b/LeStorage/Services.swift index 77c96b0..b663751 100644 --- a/LeStorage/Services.swift +++ b/LeStorage/Services.swift @@ -519,26 +519,6 @@ public class Services { return try await self._runRequest(deleteRequest) } - /// Executes a POST request - - public func post(_ instance: T) async throws -> T { - var postRequest = try self._postRequest(type: T.self) - postRequest.httpBody = try JSON.encoder.encode(instance) - return try await self._runRequest(postRequest) - } - - /// Executes a PUT request - public func put(_ instance: T) async throws -> T { - var postRequest = try self._putRequest(type: T.self, id: instance.stringId) - postRequest.httpBody = try JSON.encoder.encode(instance) - return try await self._runRequest(postRequest) - } - - public func delete(_ instance: T) async throws -> T { - let deleteRequest = try self._deleteRequest(type: T.self, id: instance.stringId) - return try await self._runRequest(deleteRequest) - } - /// Executes an ApiCall func runGetApiCall(_ apiCall: ApiCall) async throws -> V { let request = try self._syncGetRequest(from: apiCall) diff --git a/LeStorage/SyncedStorable.swift b/LeStorage/SyncedStorable.swift index 484b7a9..66f30a2 100644 --- a/LeStorage/SyncedStorable.swift +++ b/LeStorage/SyncedStorable.swift @@ -30,9 +30,7 @@ public protocol SideStorable { var storeId: String? { get set } } -extension SyncedStorable { - - public static var copyServerResponse: Bool { return false } +public extension SyncedStorable { func copy() -> Self { let copy = Self() diff --git a/LeStorage/Utils/Date+Extensions.swift b/LeStorage/Utils/Date+Extensions.swift index c3d81e6..41f6c98 100644 --- a/LeStorage/Utils/Date+Extensions.swift +++ b/LeStorage/Utils/Date+Extensions.swift @@ -9,19 +9,19 @@ import Foundation extension Date { - static var iso8601Formatter: ISO8601DateFormatter { + static var iso8601Formatter: ISO8601DateFormatter = { let iso8601Formatter = ISO8601DateFormatter() iso8601Formatter.timeZone = TimeZone(abbreviation: "CET") iso8601Formatter.formatOptions = [.withInternetDateTime, .withTimeZone] return iso8601Formatter - } + }() - public static var iso8601FractionalFormatter: ISO8601DateFormatter { + public static var iso8601FractionalFormatter: ISO8601DateFormatter = { let iso8601Formatter = ISO8601DateFormatter() iso8601Formatter.timeZone = TimeZone(abbreviation: "CET") iso8601Formatter.formatOptions = [.withInternetDateTime, .withTimeZone, .withFractionalSeconds] return iso8601Formatter - } + }() public static var microSecondFormatter: DateFormatter = { let formatter = DateFormatter()