|
|
|
|
@ -6,14 +6,13 @@ import LeStorage |
|
|
|
|
import SwiftUI |
|
|
|
|
|
|
|
|
|
@Observable |
|
|
|
|
class BaseTeamRegistration: ModelObject, SyncedStorable, Codable { |
|
|
|
|
class BaseTeamRegistration: SyncedModelObject, SyncedStorable { |
|
|
|
|
|
|
|
|
|
static func resourceName() -> String { return "team-registrations" } |
|
|
|
|
static func tokenExemptedMethods() -> [HTTPMethod] { return [] } |
|
|
|
|
static func filterByStoreIdentifier() -> Bool { return true } |
|
|
|
|
|
|
|
|
|
var id: String = Store.randomId() |
|
|
|
|
var lastUpdate: Date = Date() |
|
|
|
|
var tournament: String = "" |
|
|
|
|
var groupStage: String? = nil |
|
|
|
|
var registrationDate: Date? = nil |
|
|
|
|
@ -34,11 +33,9 @@ class BaseTeamRegistration: ModelObject, SyncedStorable, Codable { |
|
|
|
|
var qualified: Bool = false |
|
|
|
|
var finalRanking: Int? = nil |
|
|
|
|
var pointsEarned: Int? = nil |
|
|
|
|
var storeId: String? = nil |
|
|
|
|
|
|
|
|
|
init( |
|
|
|
|
id: String = Store.randomId(), |
|
|
|
|
lastUpdate: Date = Date(), |
|
|
|
|
tournament: String = "", |
|
|
|
|
groupStage: String? = nil, |
|
|
|
|
registrationDate: Date? = nil, |
|
|
|
|
@ -58,12 +55,10 @@ class BaseTeamRegistration: ModelObject, SyncedStorable, Codable { |
|
|
|
|
confirmationDate: Date? = nil, |
|
|
|
|
qualified: Bool = false, |
|
|
|
|
finalRanking: Int? = nil, |
|
|
|
|
pointsEarned: Int? = nil, |
|
|
|
|
storeId: String? = nil |
|
|
|
|
pointsEarned: Int? = nil |
|
|
|
|
) { |
|
|
|
|
super.init() |
|
|
|
|
self.id = id |
|
|
|
|
self.lastUpdate = lastUpdate |
|
|
|
|
self.tournament = tournament |
|
|
|
|
self.groupStage = groupStage |
|
|
|
|
self.registrationDate = registrationDate |
|
|
|
|
@ -84,12 +79,10 @@ class BaseTeamRegistration: ModelObject, SyncedStorable, Codable { |
|
|
|
|
self.qualified = qualified |
|
|
|
|
self.finalRanking = finalRanking |
|
|
|
|
self.pointsEarned = pointsEarned |
|
|
|
|
self.storeId = storeId |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
enum CodingKeys: String, CodingKey { |
|
|
|
|
case _id = "id" |
|
|
|
|
case _lastUpdate = "lastUpdate" |
|
|
|
|
case _tournament = "tournament" |
|
|
|
|
case _groupStage = "groupStage" |
|
|
|
|
case _registrationDate = "registrationDate" |
|
|
|
|
@ -110,15 +103,11 @@ class BaseTeamRegistration: ModelObject, SyncedStorable, Codable { |
|
|
|
|
case _qualified = "qualified" |
|
|
|
|
case _finalRanking = "finalRanking" |
|
|
|
|
case _pointsEarned = "pointsEarned" |
|
|
|
|
case _storeId = "storeId" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
required init(from decoder: Decoder) throws { |
|
|
|
|
super.init() |
|
|
|
|
let container = try decoder.container(keyedBy: CodingKeys.self) |
|
|
|
|
self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() |
|
|
|
|
let dateString = try container.decode(String.self, forKey: ._lastUpdate) |
|
|
|
|
self.lastUpdate = Date.iso8601FractionalFormatter.date(from: dateString) ?? Date() |
|
|
|
|
self.tournament = try container.decodeIfPresent(String.self, forKey: ._tournament) ?? "" |
|
|
|
|
self.groupStage = try container.decodeIfPresent(String.self, forKey: ._groupStage) ?? nil |
|
|
|
|
self.registrationDate = try container.decodeIfPresent(Date.self, forKey: ._registrationDate) ?? nil |
|
|
|
|
@ -139,13 +128,12 @@ class BaseTeamRegistration: ModelObject, SyncedStorable, Codable { |
|
|
|
|
self.qualified = try container.decodeIfPresent(Bool.self, forKey: ._qualified) ?? false |
|
|
|
|
self.finalRanking = try container.decodeIfPresent(Int.self, forKey: ._finalRanking) ?? nil |
|
|
|
|
self.pointsEarned = try container.decodeIfPresent(Int.self, forKey: ._pointsEarned) ?? nil |
|
|
|
|
self.storeId = try container.decodeIfPresent(String.self, forKey: ._storeId) ?? nil |
|
|
|
|
try super.init(from: decoder) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func encode(to encoder: Encoder) throws { |
|
|
|
|
override func encode(to encoder: Encoder) throws { |
|
|
|
|
var container = encoder.container(keyedBy: CodingKeys.self) |
|
|
|
|
try container.encode(self.id, forKey: ._id) |
|
|
|
|
try container.encode(Date.iso8601FractionalFormatter.string(from: self.lastUpdate), forKey: ._lastUpdate) |
|
|
|
|
try container.encode(self.tournament, forKey: ._tournament) |
|
|
|
|
try container.encode(self.groupStage, forKey: ._groupStage) |
|
|
|
|
try container.encode(self.registrationDate, forKey: ._registrationDate) |
|
|
|
|
@ -166,7 +154,7 @@ class BaseTeamRegistration: ModelObject, SyncedStorable, Codable { |
|
|
|
|
try container.encode(self.qualified, forKey: ._qualified) |
|
|
|
|
try container.encode(self.finalRanking, forKey: ._finalRanking) |
|
|
|
|
try container.encode(self.pointsEarned, forKey: ._pointsEarned) |
|
|
|
|
try container.encode(self.storeId, forKey: ._storeId) |
|
|
|
|
try super.encode(to: encoder) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func groupStageValue() -> GroupStage? { |
|
|
|
|
@ -177,7 +165,6 @@ class BaseTeamRegistration: ModelObject, SyncedStorable, Codable { |
|
|
|
|
func copy(from other: any Storable) { |
|
|
|
|
guard let teamregistration = other as? BaseTeamRegistration else { return } |
|
|
|
|
self.id = teamregistration.id |
|
|
|
|
self.lastUpdate = teamregistration.lastUpdate |
|
|
|
|
self.tournament = teamregistration.tournament |
|
|
|
|
self.groupStage = teamregistration.groupStage |
|
|
|
|
self.registrationDate = teamregistration.registrationDate |
|
|
|
|
@ -198,8 +185,8 @@ class BaseTeamRegistration: ModelObject, SyncedStorable, Codable { |
|
|
|
|
self.qualified = teamregistration.qualified |
|
|
|
|
self.finalRanking = teamregistration.finalRanking |
|
|
|
|
self.pointsEarned = teamregistration.pointsEarned |
|
|
|
|
self.storeId = teamregistration.storeId |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static func relationships() -> [Relationship] { |
|
|
|
|
return [ |
|
|
|
|
Relationship(type: GroupStage.self, keyPath: \BaseTeamRegistration.groupStage), |
|
|
|
|
|