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.
100 lines
3.4 KiB
100 lines
3.4 KiB
// Generated by SwiftModelGenerator
|
|
// Do not modify this file manually
|
|
|
|
import Foundation
|
|
import LeStorage
|
|
import SwiftUI
|
|
|
|
@Observable
|
|
public class BaseEvent: SyncedModelObject, SyncedStorable {
|
|
|
|
public static func resourceName() -> String { return "events" }
|
|
public static func tokenExemptedMethods() -> [HTTPMethod] { return [] }
|
|
public static var copyServerResponse: Bool = false
|
|
|
|
public var id: String = Store.randomId()
|
|
public var creator: String? = nil
|
|
public var club: String? = nil
|
|
public var creationDate: Date = Date()
|
|
public var name: String? = nil
|
|
public var tenupId: String? = nil
|
|
|
|
public init(
|
|
id: String = Store.randomId(),
|
|
creator: String? = nil,
|
|
club: String? = nil,
|
|
creationDate: Date = Date(),
|
|
name: String? = nil,
|
|
tenupId: String? = nil
|
|
) {
|
|
super.init()
|
|
self.id = id
|
|
self.creator = creator
|
|
self.club = club
|
|
self.creationDate = creationDate
|
|
self.name = name
|
|
self.tenupId = tenupId
|
|
}
|
|
required public override init() {
|
|
super.init()
|
|
}
|
|
|
|
public enum CodingKeys: String, CodingKey {
|
|
case _id = "id"
|
|
case _creator = "creator"
|
|
case _club = "club"
|
|
case _creationDate = "creationDate"
|
|
case _name = "name"
|
|
case _tenupId = "tenupId"
|
|
}
|
|
|
|
required init(from decoder: Decoder) throws {
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId()
|
|
self.creator = try container.decodeIfPresent(String.self, forKey: ._creator) ?? nil
|
|
self.club = try container.decodeIfPresent(String.self, forKey: ._club) ?? nil
|
|
self.creationDate = try container.decodeIfPresent(Date.self, forKey: ._creationDate) ?? Date()
|
|
self.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? nil
|
|
self.tenupId = try container.decodeIfPresent(String.self, forKey: ._tenupId) ?? nil
|
|
try super.init(from: decoder)
|
|
}
|
|
|
|
public override func encode(to encoder: Encoder) throws {
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
try container.encode(self.id, forKey: ._id)
|
|
try container.encode(self.creator, forKey: ._creator)
|
|
try container.encode(self.club, forKey: ._club)
|
|
try container.encode(self.creationDate, forKey: ._creationDate)
|
|
try container.encode(self.name, forKey: ._name)
|
|
try container.encode(self.tenupId, forKey: ._tenupId)
|
|
try super.encode(to: encoder)
|
|
}
|
|
|
|
func creatorValue() -> CustomUser? {
|
|
guard let creator = self.creator else { return nil }
|
|
return Store.main.findById(creator)
|
|
}
|
|
|
|
func clubValue() -> Club? {
|
|
guard let club = self.club else { return nil }
|
|
return Store.main.findById(club)
|
|
}
|
|
|
|
public func copy(from other: any Storable) {
|
|
guard let event = other as? BaseEvent else { return }
|
|
self.id = event.id
|
|
self.creator = event.creator
|
|
self.club = event.club
|
|
self.creationDate = event.creationDate
|
|
self.name = event.name
|
|
self.tenupId = event.tenupId
|
|
}
|
|
|
|
public static func relationships() -> [Relationship] {
|
|
return [
|
|
Relationship(type: CustomUser.self, keyPath: \BaseEvent.creator),
|
|
Relationship(type: Club.self, keyPath: \BaseEvent.club),
|
|
]
|
|
}
|
|
|
|
} |