You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.6 KiB
62 lines
1.6 KiB
//
|
|
// Log.swift
|
|
// LeStorage
|
|
//
|
|
// Created by Laurent Morvillier on 03/07/2024.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
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()
|
|
}
|
|
|
|
var id: String = Store.randomId()
|
|
|
|
var date: Date = Date()
|
|
|
|
var message: String = ""
|
|
|
|
init(message: String) {
|
|
self.message = message
|
|
super.init()
|
|
}
|
|
|
|
// MARK: - Codable
|
|
enum CodingKeys: String, CodingKey {
|
|
case id
|
|
case date
|
|
case message
|
|
}
|
|
|
|
required init(from decoder: Decoder) throws {
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
id = try container.decode(String.self, forKey: .id)
|
|
date = try container.decode(Date.self, forKey: .date)
|
|
message = try container.decode(String.self, forKey: .message)
|
|
try super.init(from: decoder)
|
|
}
|
|
|
|
override func encode(to encoder: Encoder) throws {
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
try container.encode(id, forKey: .id)
|
|
try container.encode(date, forKey: .date)
|
|
try container.encode(message, forKey: .message)
|
|
try super.encode(to: encoder)
|
|
}
|
|
|
|
func copy(from other: any Storable) {
|
|
guard let log = other as? Log else { return }
|
|
|
|
self.date = log.date
|
|
self.message = log.message
|
|
}
|
|
|
|
}
|
|
|