sync_v2
Laurent 6 months ago
commit fd413ff86a
  1. 1
      LeStorage/Codables/DataAccess.swift
  2. 3
      LeStorage/Codables/FailedAPICall.swift
  3. 3
      LeStorage/Codables/GetSyncData.swift
  4. 1
      LeStorage/Codables/Log.swift
  5. 4
      LeStorage/ModelObject.swift
  6. 20
      LeStorage/Services.swift
  7. 4
      LeStorage/SyncedStorable.swift
  8. 8
      LeStorage/Utils/Date+Extensions.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()

@ -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 = ""

@ -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"
}

@ -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()

@ -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()
}

@ -519,26 +519,6 @@ public class Services {
return try await self._runRequest(deleteRequest)
}
/// Executes a POST request
public func post<T: Storable>(_ 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<T: Storable>(_ 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<T: Storable>(_ 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<T: SyncedStorable, V: Decodable>(_ apiCall: ApiCall<T>) async throws -> V {
let request = try self._syncGetRequest(from: apiCall)

@ -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()

@ -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()

Loading…
Cancel
Save