Improves data generation

sync2
Laurent 11 months ago
parent 786ad5ee45
commit eb1f69ec97
  1. 2
      PadelClub/Data/Club.swift
  2. 2
      PadelClub/Data/Court.swift
  3. 2
      PadelClub/Data/CustomUser.swift
  4. 2
      PadelClub/Data/Event.swift
  5. 16
      PadelClub/Data/Gen/BaseClub.swift
  6. 16
      PadelClub/Data/Gen/BaseCourt.swift
  7. 16
      PadelClub/Data/Gen/BaseCustomUser.swift
  8. 16
      PadelClub/Data/Gen/BaseDateInterval.swift
  9. 16
      PadelClub/Data/Gen/BaseEvent.swift
  10. 25
      PadelClub/Data/Gen/BaseGroupStage.swift
  11. 25
      PadelClub/Data/Gen/BaseMatch.swift
  12. 17
      PadelClub/Data/Gen/BaseMatchScheduler.swift
  13. 8
      PadelClub/Data/Gen/BaseMonthData.swift
  14. 25
      PadelClub/Data/Gen/BasePlayerRegistration.swift
  15. 16
      PadelClub/Data/Gen/BasePurchase.swift
  16. 25
      PadelClub/Data/Gen/BaseRound.swift
  17. 25
      PadelClub/Data/Gen/BaseTeamRegistration.swift
  18. 25
      PadelClub/Data/Gen/BaseTeamScore.swift
  19. 16
      PadelClub/Data/Gen/BaseTournament.swift
  20. 5
      PadelClub/Data/Gen/Club.json
  21. 5
      PadelClub/Data/Gen/Court.json
  22. 5
      PadelClub/Data/Gen/CustomUser.json
  23. 5
      PadelClub/Data/Gen/DateInterval.json
  24. 5
      PadelClub/Data/Gen/Event.json
  25. 11
      PadelClub/Data/Gen/GroupStage.json
  26. 10
      PadelClub/Data/Gen/Match.json
  27. 5
      PadelClub/Data/Gen/MatchScheduler.json
  28. 11
      PadelClub/Data/Gen/PlayerRegistration.json
  29. 5
      PadelClub/Data/Gen/Purchase.json
  30. 11
      PadelClub/Data/Gen/Round.json
  31. 11
      PadelClub/Data/Gen/TeamRegistration.json
  32. 11
      PadelClub/Data/Gen/TeamScore.json
  33. 5
      PadelClub/Data/Gen/Tournament.json
  34. 23
      PadelClub/Data/Gen/generator.py
  35. 2
      PadelClub/Data/TeamRegistration.swift
  36. 2
      PadelClub/Data/Tournament.swift
  37. 2
      PadelClub/Views/Tournament/Subscription/Purchase.swift

@ -34,8 +34,6 @@ final class Club: BaseClub {
// var broadcastCode: String? // var broadcastCode: String?
//// var alphabeticalName: Bool = false //// var alphabeticalName: Bool = false
var storeId: String? { return nil }
internal init(creator: String? = nil, name: String, acronym: String? = nil, phone: String? = nil, code: String? = nil, address: String? = nil, city: String? = nil, zipCode: String? = nil, latitude: Double? = nil, longitude: Double? = nil, courtCount: Int = 2, broadcastCode: String? = nil) { internal init(creator: String? = nil, name: String, acronym: String? = nil, phone: String? = nil, code: String? = nil, address: String? = nil, city: String? = nil, zipCode: String? = nil, latitude: Double? = nil, longitude: Double? = nil, courtCount: Int = 2, broadcastCode: String? = nil) {
super.init() super.init()

@ -16,8 +16,6 @@ final class Court: BaseCourt {
lhs.id == rhs.id lhs.id == rhs.id
} }
var storeId: String? { return nil }
init(index: Int, club: String, name: String? = nil, exitAllowed: Bool = false, indoor: Bool = false) { init(index: Int, club: String, name: String? = nil, exitAllowed: Bool = false, indoor: Bool = false) {
super.init() super.init()

@ -48,8 +48,6 @@ class CustomUser: BaseCustomUser, UserBase {
// //
// var deviceId: String? // var deviceId: String?
var storeId: String? { return nil }
init(username: String, email: String, firstName: String, lastName: String, phone: String?, country: String?, loserBracketMode: LoserBracketMode = .automatic) { init(username: String, email: String, firstName: String, lastName: String, phone: String?, country: String?, loserBracketMode: LoserBracketMode = .automatic) {
super.init(username: username, email: email, firstName: firstName, lastName: lastName, phone: phone, country: country, loserBracketMode: loserBracketMode) super.init(username: username, email: email, firstName: firstName, lastName: lastName, phone: phone, country: country, loserBracketMode: loserBracketMode)

@ -12,8 +12,6 @@ import SwiftUI
@Observable @Observable
final class Event: BaseEvent { final class Event: BaseEvent {
var storeId: String? { return nil }
internal init(creator: String? = nil, club: String? = nil, name: String? = nil, tenupId: String? = nil) { internal init(creator: String? = nil, club: String? = nil, name: String? = nil, tenupId: String? = nil) {
super.init(creator: creator, club: club, name: name, tenupId: tenupId) super.init(creator: creator, club: club, name: name, tenupId: tenupId)

@ -6,14 +6,13 @@ import LeStorage
import SwiftUI import SwiftUI
@Observable @Observable
class BaseClub: ModelObject, SyncedStorable, Codable { class BaseClub: SyncedModelObject, SyncedStorable {
static func resourceName() -> String { return "clubs" } static func resourceName() -> String { return "clubs" }
static func tokenExemptedMethods() -> [HTTPMethod] { return [] } static func tokenExemptedMethods() -> [HTTPMethod] { return [] }
static func filterByStoreIdentifier() -> Bool { return false } static func filterByStoreIdentifier() -> Bool { return false }
var id: String = Store.randomId() var id: String = Store.randomId()
var lastUpdate: Date = Date()
var creator: String? = nil var creator: String? = nil
var name: String = "" var name: String = ""
var acronym: String = "" var acronym: String = ""
@ -29,7 +28,6 @@ class BaseClub: ModelObject, SyncedStorable, Codable {
init( init(
id: String = Store.randomId(), id: String = Store.randomId(),
lastUpdate: Date = Date(),
creator: String? = nil, creator: String? = nil,
name: String = "", name: String = "",
acronym: String = "", acronym: String = "",
@ -45,7 +43,6 @@ class BaseClub: ModelObject, SyncedStorable, Codable {
) { ) {
super.init() super.init()
self.id = id self.id = id
self.lastUpdate = lastUpdate
self.creator = creator self.creator = creator
self.name = name self.name = name
self.acronym = acronym self.acronym = acronym
@ -62,7 +59,6 @@ class BaseClub: ModelObject, SyncedStorable, Codable {
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case _id = "id" case _id = "id"
case _lastUpdate = "lastUpdate"
case _creator = "creator" case _creator = "creator"
case _name = "name" case _name = "name"
case _acronym = "acronym" case _acronym = "acronym"
@ -78,11 +74,8 @@ class BaseClub: ModelObject, SyncedStorable, Codable {
} }
required init(from decoder: Decoder) throws { required init(from decoder: Decoder) throws {
super.init()
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() 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.creator = try container.decodeIfPresent(String.self, forKey: ._creator) ?? nil self.creator = try container.decodeIfPresent(String.self, forKey: ._creator) ?? nil
self.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? "" self.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? ""
self.acronym = try container.decodeIfPresent(String.self, forKey: ._acronym) ?? "" self.acronym = try container.decodeIfPresent(String.self, forKey: ._acronym) ?? ""
@ -95,12 +88,12 @@ class BaseClub: ModelObject, SyncedStorable, Codable {
self.longitude = try container.decodeIfPresent(Double.self, forKey: ._longitude) ?? nil self.longitude = try container.decodeIfPresent(Double.self, forKey: ._longitude) ?? nil
self.courtCount = try container.decodeIfPresent(Int.self, forKey: ._courtCount) ?? 2 self.courtCount = try container.decodeIfPresent(Int.self, forKey: ._courtCount) ?? 2
self.broadcastCode = try container.decodeIfPresent(String.self, forKey: ._broadcastCode) ?? nil self.broadcastCode = try container.decodeIfPresent(String.self, forKey: ._broadcastCode) ?? 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) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.id, forKey: ._id) try container.encode(self.id, forKey: ._id)
try container.encode(Date.iso8601FractionalFormatter.string(from: self.lastUpdate), forKey: ._lastUpdate)
try container.encode(self.creator, forKey: ._creator) try container.encode(self.creator, forKey: ._creator)
try container.encode(self.name, forKey: ._name) try container.encode(self.name, forKey: ._name)
try container.encode(self.acronym, forKey: ._acronym) try container.encode(self.acronym, forKey: ._acronym)
@ -113,6 +106,7 @@ class BaseClub: ModelObject, SyncedStorable, Codable {
try container.encode(self.longitude, forKey: ._longitude) try container.encode(self.longitude, forKey: ._longitude)
try container.encode(self.courtCount, forKey: ._courtCount) try container.encode(self.courtCount, forKey: ._courtCount)
try container.encode(self.broadcastCode, forKey: ._broadcastCode) try container.encode(self.broadcastCode, forKey: ._broadcastCode)
try super.encode(to: encoder)
} }
func creatorValue() -> CustomUser? { func creatorValue() -> CustomUser? {
@ -123,7 +117,6 @@ class BaseClub: ModelObject, SyncedStorable, Codable {
func copy(from other: any Storable) { func copy(from other: any Storable) {
guard let club = other as? BaseClub else { return } guard let club = other as? BaseClub else { return }
self.id = club.id self.id = club.id
self.lastUpdate = club.lastUpdate
self.creator = club.creator self.creator = club.creator
self.name = club.name self.name = club.name
self.acronym = club.acronym self.acronym = club.acronym
@ -137,6 +130,7 @@ class BaseClub: ModelObject, SyncedStorable, Codable {
self.courtCount = club.courtCount self.courtCount = club.courtCount
self.broadcastCode = club.broadcastCode self.broadcastCode = club.broadcastCode
} }
static func relationships() -> [Relationship] { static func relationships() -> [Relationship] {
return [ return [
Relationship(type: CustomUser.self, keyPath: \BaseClub.creator), Relationship(type: CustomUser.self, keyPath: \BaseClub.creator),

@ -6,14 +6,13 @@ import LeStorage
import SwiftUI import SwiftUI
@Observable @Observable
class BaseCourt: ModelObject, SyncedStorable, Codable { class BaseCourt: SyncedModelObject, SyncedStorable {
static func resourceName() -> String { return "courts" } static func resourceName() -> String { return "courts" }
static func tokenExemptedMethods() -> [HTTPMethod] { return [] } static func tokenExemptedMethods() -> [HTTPMethod] { return [] }
static func filterByStoreIdentifier() -> Bool { return false } static func filterByStoreIdentifier() -> Bool { return false }
var id: String = Store.randomId() var id: String = Store.randomId()
var lastUpdate: Date = Date()
var index: Int = 0 var index: Int = 0
var club: String = "" var club: String = ""
var name: String? = nil var name: String? = nil
@ -22,7 +21,6 @@ class BaseCourt: ModelObject, SyncedStorable, Codable {
init( init(
id: String = Store.randomId(), id: String = Store.randomId(),
lastUpdate: Date = Date(),
index: Int = 0, index: Int = 0,
club: String = "", club: String = "",
name: String? = nil, name: String? = nil,
@ -31,7 +29,6 @@ class BaseCourt: ModelObject, SyncedStorable, Codable {
) { ) {
super.init() super.init()
self.id = id self.id = id
self.lastUpdate = lastUpdate
self.index = index self.index = index
self.club = club self.club = club
self.name = name self.name = name
@ -41,7 +38,6 @@ class BaseCourt: ModelObject, SyncedStorable, Codable {
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case _id = "id" case _id = "id"
case _lastUpdate = "lastUpdate"
case _index = "index" case _index = "index"
case _club = "club" case _club = "club"
case _name = "name" case _name = "name"
@ -50,27 +46,25 @@ class BaseCourt: ModelObject, SyncedStorable, Codable {
} }
required init(from decoder: Decoder) throws { required init(from decoder: Decoder) throws {
super.init()
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() 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.index = try container.decodeIfPresent(Int.self, forKey: ._index) ?? 0 self.index = try container.decodeIfPresent(Int.self, forKey: ._index) ?? 0
self.club = try container.decodeIfPresent(String.self, forKey: ._club) ?? "" self.club = try container.decodeIfPresent(String.self, forKey: ._club) ?? ""
self.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? nil self.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? nil
self.exitAllowed = try container.decodeIfPresent(Bool.self, forKey: ._exitAllowed) ?? false self.exitAllowed = try container.decodeIfPresent(Bool.self, forKey: ._exitAllowed) ?? false
self.indoor = try container.decodeIfPresent(Bool.self, forKey: ._indoor) ?? false self.indoor = try container.decodeIfPresent(Bool.self, forKey: ._indoor) ?? false
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) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.id, forKey: ._id) try container.encode(self.id, forKey: ._id)
try container.encode(Date.iso8601FractionalFormatter.string(from: self.lastUpdate), forKey: ._lastUpdate)
try container.encode(self.index, forKey: ._index) try container.encode(self.index, forKey: ._index)
try container.encode(self.club, forKey: ._club) try container.encode(self.club, forKey: ._club)
try container.encode(self.name, forKey: ._name) try container.encode(self.name, forKey: ._name)
try container.encode(self.exitAllowed, forKey: ._exitAllowed) try container.encode(self.exitAllowed, forKey: ._exitAllowed)
try container.encode(self.indoor, forKey: ._indoor) try container.encode(self.indoor, forKey: ._indoor)
try super.encode(to: encoder)
} }
func clubValue() -> Club? { func clubValue() -> Club? {
@ -80,13 +74,13 @@ class BaseCourt: ModelObject, SyncedStorable, Codable {
func copy(from other: any Storable) { func copy(from other: any Storable) {
guard let court = other as? BaseCourt else { return } guard let court = other as? BaseCourt else { return }
self.id = court.id self.id = court.id
self.lastUpdate = court.lastUpdate
self.index = court.index self.index = court.index
self.club = court.club self.club = court.club
self.name = court.name self.name = court.name
self.exitAllowed = court.exitAllowed self.exitAllowed = court.exitAllowed
self.indoor = court.indoor self.indoor = court.indoor
} }
static func relationships() -> [Relationship] { static func relationships() -> [Relationship] {
return [ return [
Relationship(type: Club.self, keyPath: \BaseCourt.club), Relationship(type: Club.self, keyPath: \BaseCourt.club),

@ -6,14 +6,13 @@ import LeStorage
import SwiftUI import SwiftUI
@Observable @Observable
class BaseCustomUser: ModelObject, SyncedStorable, Codable { class BaseCustomUser: SyncedModelObject, SyncedStorable {
static func resourceName() -> String { return "users" } static func resourceName() -> String { return "users" }
static func tokenExemptedMethods() -> [HTTPMethod] { return [.post] } static func tokenExemptedMethods() -> [HTTPMethod] { return [.post] }
static func filterByStoreIdentifier() -> Bool { return false } static func filterByStoreIdentifier() -> Bool { return false }
var id: String = Store.randomId() var id: String = Store.randomId()
var lastUpdate: Date = Date()
var username: String = "" var username: String = ""
var email: String = "" var email: String = ""
var clubs: [String] = [] var clubs: [String] = []
@ -38,7 +37,6 @@ class BaseCustomUser: ModelObject, SyncedStorable, Codable {
init( init(
id: String = Store.randomId(), id: String = Store.randomId(),
lastUpdate: Date = Date(),
username: String = "", username: String = "",
email: String = "", email: String = "",
clubs: [String] = [], clubs: [String] = [],
@ -63,7 +61,6 @@ class BaseCustomUser: ModelObject, SyncedStorable, Codable {
) { ) {
super.init() super.init()
self.id = id self.id = id
self.lastUpdate = lastUpdate
self.username = username self.username = username
self.email = email self.email = email
self.clubs = clubs self.clubs = clubs
@ -89,7 +86,6 @@ class BaseCustomUser: ModelObject, SyncedStorable, Codable {
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case _id = "id" case _id = "id"
case _lastUpdate = "lastUpdate"
case _username = "username" case _username = "username"
case _email = "email" case _email = "email"
case _clubs = "clubs" case _clubs = "clubs"
@ -114,11 +110,8 @@ class BaseCustomUser: ModelObject, SyncedStorable, Codable {
} }
required init(from decoder: Decoder) throws { required init(from decoder: Decoder) throws {
super.init()
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() 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.username = try container.decodeIfPresent(String.self, forKey: ._username) ?? "" self.username = try container.decodeIfPresent(String.self, forKey: ._username) ?? ""
self.email = try container.decodeIfPresent(String.self, forKey: ._email) ?? "" self.email = try container.decodeIfPresent(String.self, forKey: ._email) ?? ""
self.clubs = try container.decodeIfPresent([String].self, forKey: ._clubs) ?? [] self.clubs = try container.decodeIfPresent([String].self, forKey: ._clubs) ?? []
@ -140,12 +133,12 @@ class BaseCustomUser: ModelObject, SyncedStorable, Codable {
self.loserBracketMatchFormatPreference = try container.decodeIfPresent(MatchFormat.self, forKey: ._loserBracketMatchFormatPreference) ?? nil self.loserBracketMatchFormatPreference = try container.decodeIfPresent(MatchFormat.self, forKey: ._loserBracketMatchFormatPreference) ?? nil
self.loserBracketMode = try container.decodeIfPresent(LoserBracketMode.self, forKey: ._loserBracketMode) ?? .automatic self.loserBracketMode = try container.decodeIfPresent(LoserBracketMode.self, forKey: ._loserBracketMode) ?? .automatic
self.deviceId = try container.decodeIfPresent(String.self, forKey: ._deviceId) ?? nil self.deviceId = try container.decodeIfPresent(String.self, forKey: ._deviceId) ?? 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) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.id, forKey: ._id) try container.encode(self.id, forKey: ._id)
try container.encode(Date.iso8601FractionalFormatter.string(from: self.lastUpdate), forKey: ._lastUpdate)
try container.encode(self.username, forKey: ._username) try container.encode(self.username, forKey: ._username)
try container.encode(self.email, forKey: ._email) try container.encode(self.email, forKey: ._email)
try container.encode(self.clubs, forKey: ._clubs) try container.encode(self.clubs, forKey: ._clubs)
@ -167,12 +160,12 @@ class BaseCustomUser: ModelObject, SyncedStorable, Codable {
try container.encode(self.loserBracketMatchFormatPreference, forKey: ._loserBracketMatchFormatPreference) try container.encode(self.loserBracketMatchFormatPreference, forKey: ._loserBracketMatchFormatPreference)
try container.encode(self.loserBracketMode, forKey: ._loserBracketMode) try container.encode(self.loserBracketMode, forKey: ._loserBracketMode)
try container.encode(self.deviceId, forKey: ._deviceId) try container.encode(self.deviceId, forKey: ._deviceId)
try super.encode(to: encoder)
} }
func copy(from other: any Storable) { func copy(from other: any Storable) {
guard let customuser = other as? BaseCustomUser else { return } guard let customuser = other as? BaseCustomUser else { return }
self.id = customuser.id self.id = customuser.id
self.lastUpdate = customuser.lastUpdate
self.username = customuser.username self.username = customuser.username
self.email = customuser.email self.email = customuser.email
self.clubs = customuser.clubs self.clubs = customuser.clubs
@ -195,6 +188,7 @@ class BaseCustomUser: ModelObject, SyncedStorable, Codable {
self.loserBracketMode = customuser.loserBracketMode self.loserBracketMode = customuser.loserBracketMode
self.deviceId = customuser.deviceId self.deviceId = customuser.deviceId
} }
static func relationships() -> [Relationship] { static func relationships() -> [Relationship] {
return [] return []
} }

@ -6,14 +6,13 @@ import LeStorage
import SwiftUI import SwiftUI
@Observable @Observable
class BaseDateInterval: ModelObject, SyncedStorable, Codable { class BaseDateInterval: SyncedModelObject, SyncedStorable {
static func resourceName() -> String { return "date-intervals" } static func resourceName() -> String { return "date-intervals" }
static func tokenExemptedMethods() -> [HTTPMethod] { return [] } static func tokenExemptedMethods() -> [HTTPMethod] { return [] }
static func filterByStoreIdentifier() -> Bool { return false } static func filterByStoreIdentifier() -> Bool { return false }
var id: String = Store.randomId() var id: String = Store.randomId()
var lastUpdate: Date = Date()
var event: String = "" var event: String = ""
var courtIndex: Int = 0 var courtIndex: Int = 0
var startDate: Date = Date() var startDate: Date = Date()
@ -21,7 +20,6 @@ class BaseDateInterval: ModelObject, SyncedStorable, Codable {
init( init(
id: String = Store.randomId(), id: String = Store.randomId(),
lastUpdate: Date = Date(),
event: String = "", event: String = "",
courtIndex: Int = 0, courtIndex: Int = 0,
startDate: Date = Date(), startDate: Date = Date(),
@ -29,7 +27,6 @@ class BaseDateInterval: ModelObject, SyncedStorable, Codable {
) { ) {
super.init() super.init()
self.id = id self.id = id
self.lastUpdate = lastUpdate
self.event = event self.event = event
self.courtIndex = courtIndex self.courtIndex = courtIndex
self.startDate = startDate self.startDate = startDate
@ -38,7 +35,6 @@ class BaseDateInterval: ModelObject, SyncedStorable, Codable {
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case _id = "id" case _id = "id"
case _lastUpdate = "lastUpdate"
case _event = "event" case _event = "event"
case _courtIndex = "courtIndex" case _courtIndex = "courtIndex"
case _startDate = "startDate" case _startDate = "startDate"
@ -46,36 +42,34 @@ class BaseDateInterval: ModelObject, SyncedStorable, Codable {
} }
required init(from decoder: Decoder) throws { required init(from decoder: Decoder) throws {
super.init()
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() 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.event = try container.decodeIfPresent(String.self, forKey: ._event) ?? "" self.event = try container.decodeIfPresent(String.self, forKey: ._event) ?? ""
self.courtIndex = try container.decodeIfPresent(Int.self, forKey: ._courtIndex) ?? 0 self.courtIndex = try container.decodeIfPresent(Int.self, forKey: ._courtIndex) ?? 0
self.startDate = try container.decodeIfPresent(Date.self, forKey: ._startDate) ?? Date() self.startDate = try container.decodeIfPresent(Date.self, forKey: ._startDate) ?? Date()
self.endDate = try container.decodeIfPresent(Date.self, forKey: ._endDate) ?? Date() self.endDate = try container.decodeIfPresent(Date.self, forKey: ._endDate) ?? Date()
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) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.id, forKey: ._id) try container.encode(self.id, forKey: ._id)
try container.encode(Date.iso8601FractionalFormatter.string(from: self.lastUpdate), forKey: ._lastUpdate)
try container.encode(self.event, forKey: ._event) try container.encode(self.event, forKey: ._event)
try container.encode(self.courtIndex, forKey: ._courtIndex) try container.encode(self.courtIndex, forKey: ._courtIndex)
try container.encode(self.startDate, forKey: ._startDate) try container.encode(self.startDate, forKey: ._startDate)
try container.encode(self.endDate, forKey: ._endDate) try container.encode(self.endDate, forKey: ._endDate)
try super.encode(to: encoder)
} }
func copy(from other: any Storable) { func copy(from other: any Storable) {
guard let dateinterval = other as? BaseDateInterval else { return } guard let dateinterval = other as? BaseDateInterval else { return }
self.id = dateinterval.id self.id = dateinterval.id
self.lastUpdate = dateinterval.lastUpdate
self.event = dateinterval.event self.event = dateinterval.event
self.courtIndex = dateinterval.courtIndex self.courtIndex = dateinterval.courtIndex
self.startDate = dateinterval.startDate self.startDate = dateinterval.startDate
self.endDate = dateinterval.endDate self.endDate = dateinterval.endDate
} }
static func relationships() -> [Relationship] { static func relationships() -> [Relationship] {
return [] return []
} }

@ -6,14 +6,13 @@ import LeStorage
import SwiftUI import SwiftUI
@Observable @Observable
class BaseEvent: ModelObject, SyncedStorable, Codable { class BaseEvent: SyncedModelObject, SyncedStorable {
static func resourceName() -> String { return "events" } static func resourceName() -> String { return "events" }
static func tokenExemptedMethods() -> [HTTPMethod] { return [] } static func tokenExemptedMethods() -> [HTTPMethod] { return [] }
static func filterByStoreIdentifier() -> Bool { return false } static func filterByStoreIdentifier() -> Bool { return false }
var id: String = Store.randomId() var id: String = Store.randomId()
var lastUpdate: Date = Date()
var creator: String? = nil var creator: String? = nil
var club: String? = nil var club: String? = nil
var creationDate: Date = Date() var creationDate: Date = Date()
@ -22,7 +21,6 @@ class BaseEvent: ModelObject, SyncedStorable, Codable {
init( init(
id: String = Store.randomId(), id: String = Store.randomId(),
lastUpdate: Date = Date(),
creator: String? = nil, creator: String? = nil,
club: String? = nil, club: String? = nil,
creationDate: Date = Date(), creationDate: Date = Date(),
@ -31,7 +29,6 @@ class BaseEvent: ModelObject, SyncedStorable, Codable {
) { ) {
super.init() super.init()
self.id = id self.id = id
self.lastUpdate = lastUpdate
self.creator = creator self.creator = creator
self.club = club self.club = club
self.creationDate = creationDate self.creationDate = creationDate
@ -41,7 +38,6 @@ class BaseEvent: ModelObject, SyncedStorable, Codable {
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case _id = "id" case _id = "id"
case _lastUpdate = "lastUpdate"
case _creator = "creator" case _creator = "creator"
case _club = "club" case _club = "club"
case _creationDate = "creationDate" case _creationDate = "creationDate"
@ -50,27 +46,25 @@ class BaseEvent: ModelObject, SyncedStorable, Codable {
} }
required init(from decoder: Decoder) throws { required init(from decoder: Decoder) throws {
super.init()
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() 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.creator = try container.decodeIfPresent(String.self, forKey: ._creator) ?? nil self.creator = try container.decodeIfPresent(String.self, forKey: ._creator) ?? nil
self.club = try container.decodeIfPresent(String.self, forKey: ._club) ?? nil self.club = try container.decodeIfPresent(String.self, forKey: ._club) ?? nil
self.creationDate = try container.decodeIfPresent(Date.self, forKey: ._creationDate) ?? Date() self.creationDate = try container.decodeIfPresent(Date.self, forKey: ._creationDate) ?? Date()
self.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? nil self.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? nil
self.tenupId = try container.decodeIfPresent(String.self, forKey: ._tenupId) ?? nil self.tenupId = try container.decodeIfPresent(String.self, forKey: ._tenupId) ?? 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) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.id, forKey: ._id) try container.encode(self.id, forKey: ._id)
try container.encode(Date.iso8601FractionalFormatter.string(from: self.lastUpdate), forKey: ._lastUpdate)
try container.encode(self.creator, forKey: ._creator) try container.encode(self.creator, forKey: ._creator)
try container.encode(self.club, forKey: ._club) try container.encode(self.club, forKey: ._club)
try container.encode(self.creationDate, forKey: ._creationDate) try container.encode(self.creationDate, forKey: ._creationDate)
try container.encode(self.name, forKey: ._name) try container.encode(self.name, forKey: ._name)
try container.encode(self.tenupId, forKey: ._tenupId) try container.encode(self.tenupId, forKey: ._tenupId)
try super.encode(to: encoder)
} }
func creatorValue() -> CustomUser? { func creatorValue() -> CustomUser? {
@ -86,13 +80,13 @@ class BaseEvent: ModelObject, SyncedStorable, Codable {
func copy(from other: any Storable) { func copy(from other: any Storable) {
guard let event = other as? BaseEvent else { return } guard let event = other as? BaseEvent else { return }
self.id = event.id self.id = event.id
self.lastUpdate = event.lastUpdate
self.creator = event.creator self.creator = event.creator
self.club = event.club self.club = event.club
self.creationDate = event.creationDate self.creationDate = event.creationDate
self.name = event.name self.name = event.name
self.tenupId = event.tenupId self.tenupId = event.tenupId
} }
static func relationships() -> [Relationship] { static func relationships() -> [Relationship] {
return [ return [
Relationship(type: CustomUser.self, keyPath: \BaseEvent.creator), Relationship(type: CustomUser.self, keyPath: \BaseEvent.creator),

@ -6,14 +6,13 @@ import LeStorage
import SwiftUI import SwiftUI
@Observable @Observable
class BaseGroupStage: ModelObject, SyncedStorable, Codable { class BaseGroupStage: SyncedModelObject, SyncedStorable {
static func resourceName() -> String { return "group-stages" } static func resourceName() -> String { return "group-stages" }
static func tokenExemptedMethods() -> [HTTPMethod] { return [] } static func tokenExemptedMethods() -> [HTTPMethod] { return [] }
static func filterByStoreIdentifier() -> Bool { return true } static func filterByStoreIdentifier() -> Bool { return true }
var id: String = Store.randomId() var id: String = Store.randomId()
var lastUpdate: Date = Date()
var tournament: String = "" var tournament: String = ""
var index: Int = 0 var index: Int = 0
var size: Int = 0 var size: Int = 0
@ -21,23 +20,19 @@ class BaseGroupStage: ModelObject, SyncedStorable, Codable {
var startDate: Date? = nil var startDate: Date? = nil
var name: String? = nil var name: String? = nil
var step: Int = 0 var step: Int = 0
var storeId: String? = nil
init( init(
id: String = Store.randomId(), id: String = Store.randomId(),
lastUpdate: Date = Date(),
tournament: String = "", tournament: String = "",
index: Int = 0, index: Int = 0,
size: Int = 0, size: Int = 0,
format: MatchFormat? = nil, format: MatchFormat? = nil,
startDate: Date? = nil, startDate: Date? = nil,
name: String? = nil, name: String? = nil,
step: Int = 0, step: Int = 0
storeId: String? = nil
) { ) {
super.init() super.init()
self.id = id self.id = id
self.lastUpdate = lastUpdate
self.tournament = tournament self.tournament = tournament
self.index = index self.index = index
self.size = size self.size = size
@ -45,12 +40,10 @@ class BaseGroupStage: ModelObject, SyncedStorable, Codable {
self.startDate = startDate self.startDate = startDate
self.name = name self.name = name
self.step = step self.step = step
self.storeId = storeId
} }
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case _id = "id" case _id = "id"
case _lastUpdate = "lastUpdate"
case _tournament = "tournament" case _tournament = "tournament"
case _index = "index" case _index = "index"
case _size = "size" case _size = "size"
@ -58,15 +51,11 @@ class BaseGroupStage: ModelObject, SyncedStorable, Codable {
case _startDate = "startDate" case _startDate = "startDate"
case _name = "name" case _name = "name"
case _step = "step" case _step = "step"
case _storeId = "storeId"
} }
required init(from decoder: Decoder) throws { required init(from decoder: Decoder) throws {
super.init()
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() 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.tournament = try container.decodeIfPresent(String.self, forKey: ._tournament) ?? ""
self.index = try container.decodeIfPresent(Int.self, forKey: ._index) ?? 0 self.index = try container.decodeIfPresent(Int.self, forKey: ._index) ?? 0
self.size = try container.decodeIfPresent(Int.self, forKey: ._size) ?? 0 self.size = try container.decodeIfPresent(Int.self, forKey: ._size) ?? 0
@ -74,13 +63,12 @@ class BaseGroupStage: ModelObject, SyncedStorable, Codable {
self.startDate = try container.decodeIfPresent(Date.self, forKey: ._startDate) ?? nil self.startDate = try container.decodeIfPresent(Date.self, forKey: ._startDate) ?? nil
self.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? nil self.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? nil
self.step = try container.decodeIfPresent(Int.self, forKey: ._step) ?? 0 self.step = try container.decodeIfPresent(Int.self, forKey: ._step) ?? 0
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) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.id, forKey: ._id) 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.tournament, forKey: ._tournament)
try container.encode(self.index, forKey: ._index) try container.encode(self.index, forKey: ._index)
try container.encode(self.size, forKey: ._size) try container.encode(self.size, forKey: ._size)
@ -88,7 +76,7 @@ class BaseGroupStage: ModelObject, SyncedStorable, Codable {
try container.encode(self.startDate, forKey: ._startDate) try container.encode(self.startDate, forKey: ._startDate)
try container.encode(self.name, forKey: ._name) try container.encode(self.name, forKey: ._name)
try container.encode(self.step, forKey: ._step) try container.encode(self.step, forKey: ._step)
try container.encode(self.storeId, forKey: ._storeId) try super.encode(to: encoder)
} }
func tournamentValue() -> Tournament? { func tournamentValue() -> Tournament? {
@ -98,7 +86,6 @@ class BaseGroupStage: ModelObject, SyncedStorable, Codable {
func copy(from other: any Storable) { func copy(from other: any Storable) {
guard let groupstage = other as? BaseGroupStage else { return } guard let groupstage = other as? BaseGroupStage else { return }
self.id = groupstage.id self.id = groupstage.id
self.lastUpdate = groupstage.lastUpdate
self.tournament = groupstage.tournament self.tournament = groupstage.tournament
self.index = groupstage.index self.index = groupstage.index
self.size = groupstage.size self.size = groupstage.size
@ -106,8 +93,8 @@ class BaseGroupStage: ModelObject, SyncedStorable, Codable {
self.startDate = groupstage.startDate self.startDate = groupstage.startDate
self.name = groupstage.name self.name = groupstage.name
self.step = groupstage.step self.step = groupstage.step
self.storeId = groupstage.storeId
} }
static func relationships() -> [Relationship] { static func relationships() -> [Relationship] {
return [ return [
Relationship(type: Tournament.self, keyPath: \BaseGroupStage.tournament), Relationship(type: Tournament.self, keyPath: \BaseGroupStage.tournament),

@ -6,14 +6,13 @@ import LeStorage
import SwiftUI import SwiftUI
@Observable @Observable
class BaseMatch: ModelObject, SyncedStorable, Codable { class BaseMatch: SyncedModelObject, SyncedStorable {
static func resourceName() -> String { return "matches" } static func resourceName() -> String { return "matches" }
static func tokenExemptedMethods() -> [HTTPMethod] { return [] } static func tokenExemptedMethods() -> [HTTPMethod] { return [] }
static func filterByStoreIdentifier() -> Bool { return true } static func filterByStoreIdentifier() -> Bool { return true }
var id: String = Store.randomId() var id: String = Store.randomId()
var lastUpdate: Date = Date()
var round: String? = nil var round: String? = nil
var groupStage: String? = nil var groupStage: String? = nil
var startDate: Date? = nil var startDate: Date? = nil
@ -27,11 +26,9 @@ class BaseMatch: ModelObject, SyncedStorable, Codable {
var disabled: Bool = false var disabled: Bool = false
var courtIndex: Int? = nil var courtIndex: Int? = nil
var confirmed: Bool = false var confirmed: Bool = false
var storeId: String? = nil
init( init(
id: String = Store.randomId(), id: String = Store.randomId(),
lastUpdate: Date = Date(),
round: String? = nil, round: String? = nil,
groupStage: String? = nil, groupStage: String? = nil,
startDate: Date? = nil, startDate: Date? = nil,
@ -44,12 +41,10 @@ class BaseMatch: ModelObject, SyncedStorable, Codable {
name: String? = nil, name: String? = nil,
disabled: Bool = false, disabled: Bool = false,
courtIndex: Int? = nil, courtIndex: Int? = nil,
confirmed: Bool = false, confirmed: Bool = false
storeId: String? = nil
) { ) {
super.init() super.init()
self.id = id self.id = id
self.lastUpdate = lastUpdate
self.round = round self.round = round
self.groupStage = groupStage self.groupStage = groupStage
self.startDate = startDate self.startDate = startDate
@ -63,12 +58,10 @@ class BaseMatch: ModelObject, SyncedStorable, Codable {
self.disabled = disabled self.disabled = disabled
self.courtIndex = courtIndex self.courtIndex = courtIndex
self.confirmed = confirmed self.confirmed = confirmed
self.storeId = storeId
} }
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case _id = "id" case _id = "id"
case _lastUpdate = "lastUpdate"
case _round = "round" case _round = "round"
case _groupStage = "groupStage" case _groupStage = "groupStage"
case _startDate = "startDate" case _startDate = "startDate"
@ -82,15 +75,11 @@ class BaseMatch: ModelObject, SyncedStorable, Codable {
case _disabled = "disabled" case _disabled = "disabled"
case _courtIndex = "courtIndex" case _courtIndex = "courtIndex"
case _confirmed = "confirmed" case _confirmed = "confirmed"
case _storeId = "storeId"
} }
required init(from decoder: Decoder) throws { required init(from decoder: Decoder) throws {
super.init()
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() 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.round = try container.decodeIfPresent(String.self, forKey: ._round) ?? nil self.round = try container.decodeIfPresent(String.self, forKey: ._round) ?? nil
self.groupStage = try container.decodeIfPresent(String.self, forKey: ._groupStage) ?? nil self.groupStage = try container.decodeIfPresent(String.self, forKey: ._groupStage) ?? nil
self.startDate = try container.decodeIfPresent(Date.self, forKey: ._startDate) ?? nil self.startDate = try container.decodeIfPresent(Date.self, forKey: ._startDate) ?? nil
@ -104,13 +93,12 @@ class BaseMatch: ModelObject, SyncedStorable, Codable {
self.disabled = try container.decodeIfPresent(Bool.self, forKey: ._disabled) ?? false self.disabled = try container.decodeIfPresent(Bool.self, forKey: ._disabled) ?? false
self.courtIndex = try container.decodeIfPresent(Int.self, forKey: ._courtIndex) ?? nil self.courtIndex = try container.decodeIfPresent(Int.self, forKey: ._courtIndex) ?? nil
self.confirmed = try container.decodeIfPresent(Bool.self, forKey: ._confirmed) ?? false self.confirmed = try container.decodeIfPresent(Bool.self, forKey: ._confirmed) ?? false
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) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.id, forKey: ._id) try container.encode(self.id, forKey: ._id)
try container.encode(Date.iso8601FractionalFormatter.string(from: self.lastUpdate), forKey: ._lastUpdate)
try container.encode(self.round, forKey: ._round) try container.encode(self.round, forKey: ._round)
try container.encode(self.groupStage, forKey: ._groupStage) try container.encode(self.groupStage, forKey: ._groupStage)
try container.encode(self.startDate, forKey: ._startDate) try container.encode(self.startDate, forKey: ._startDate)
@ -124,7 +112,7 @@ class BaseMatch: ModelObject, SyncedStorable, Codable {
try container.encode(self.disabled, forKey: ._disabled) try container.encode(self.disabled, forKey: ._disabled)
try container.encode(self.courtIndex, forKey: ._courtIndex) try container.encode(self.courtIndex, forKey: ._courtIndex)
try container.encode(self.confirmed, forKey: ._confirmed) try container.encode(self.confirmed, forKey: ._confirmed)
try container.encode(self.storeId, forKey: ._storeId) try super.encode(to: encoder)
} }
func roundValue() -> Round? { func roundValue() -> Round? {
@ -140,7 +128,6 @@ class BaseMatch: ModelObject, SyncedStorable, Codable {
func copy(from other: any Storable) { func copy(from other: any Storable) {
guard let match = other as? BaseMatch else { return } guard let match = other as? BaseMatch else { return }
self.id = match.id self.id = match.id
self.lastUpdate = match.lastUpdate
self.round = match.round self.round = match.round
self.groupStage = match.groupStage self.groupStage = match.groupStage
self.startDate = match.startDate self.startDate = match.startDate
@ -154,8 +141,8 @@ class BaseMatch: ModelObject, SyncedStorable, Codable {
self.disabled = match.disabled self.disabled = match.disabled
self.courtIndex = match.courtIndex self.courtIndex = match.courtIndex
self.confirmed = match.confirmed self.confirmed = match.confirmed
self.storeId = match.storeId
} }
static func relationships() -> [Relationship] { static func relationships() -> [Relationship] {
return [ return [
Relationship(type: Round.self, keyPath: \BaseMatch.round), Relationship(type: Round.self, keyPath: \BaseMatch.round),

@ -6,7 +6,7 @@ import LeStorage
import SwiftUI import SwiftUI
@Observable @Observable
class BaseMatchScheduler: ModelObject, Storable, Codable { class BaseMatchScheduler: BaseModelObject, Storable {
static func resourceName() -> String { return "match-scheduler" } static func resourceName() -> String { return "match-scheduler" }
static func tokenExemptedMethods() -> [HTTPMethod] { return [] } static func tokenExemptedMethods() -> [HTTPMethod] { return [] }
@ -26,7 +26,6 @@ class BaseMatchScheduler: ModelObject, Storable, Codable {
var groupStageChunkCount: Int? = nil var groupStageChunkCount: Int? = nil
var overrideCourtsUnavailability: Bool = false var overrideCourtsUnavailability: Bool = false
var shouldTryToFillUpCourtsAvailable: Bool = false var shouldTryToFillUpCourtsAvailable: Bool = false
var storeId: String? = nil
init( init(
id: String = Store.randomId(), id: String = Store.randomId(),
@ -42,8 +41,7 @@ class BaseMatchScheduler: ModelObject, Storable, Codable {
shouldEndRoundBeforeStartingNext: Bool = false, shouldEndRoundBeforeStartingNext: Bool = false,
groupStageChunkCount: Int? = nil, groupStageChunkCount: Int? = nil,
overrideCourtsUnavailability: Bool = false, overrideCourtsUnavailability: Bool = false,
shouldTryToFillUpCourtsAvailable: Bool = false, shouldTryToFillUpCourtsAvailable: Bool = false
storeId: String? = nil
) { ) {
super.init() super.init()
self.id = id self.id = id
@ -60,7 +58,6 @@ class BaseMatchScheduler: ModelObject, Storable, Codable {
self.groupStageChunkCount = groupStageChunkCount self.groupStageChunkCount = groupStageChunkCount
self.overrideCourtsUnavailability = overrideCourtsUnavailability self.overrideCourtsUnavailability = overrideCourtsUnavailability
self.shouldTryToFillUpCourtsAvailable = shouldTryToFillUpCourtsAvailable self.shouldTryToFillUpCourtsAvailable = shouldTryToFillUpCourtsAvailable
self.storeId = storeId
} }
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
@ -78,11 +75,9 @@ class BaseMatchScheduler: ModelObject, Storable, Codable {
case _groupStageChunkCount = "groupStageChunkCount" case _groupStageChunkCount = "groupStageChunkCount"
case _overrideCourtsUnavailability = "overrideCourtsUnavailability" case _overrideCourtsUnavailability = "overrideCourtsUnavailability"
case _shouldTryToFillUpCourtsAvailable = "shouldTryToFillUpCourtsAvailable" case _shouldTryToFillUpCourtsAvailable = "shouldTryToFillUpCourtsAvailable"
case _storeId = "storeId"
} }
required init(from decoder: Decoder) throws { required init(from decoder: Decoder) throws {
super.init()
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId()
self.tournament = try container.decodeIfPresent(String.self, forKey: ._tournament) ?? "" self.tournament = try container.decodeIfPresent(String.self, forKey: ._tournament) ?? ""
@ -98,10 +93,10 @@ class BaseMatchScheduler: ModelObject, Storable, Codable {
self.groupStageChunkCount = try container.decodeIfPresent(Int.self, forKey: ._groupStageChunkCount) ?? nil self.groupStageChunkCount = try container.decodeIfPresent(Int.self, forKey: ._groupStageChunkCount) ?? nil
self.overrideCourtsUnavailability = try container.decodeIfPresent(Bool.self, forKey: ._overrideCourtsUnavailability) ?? false self.overrideCourtsUnavailability = try container.decodeIfPresent(Bool.self, forKey: ._overrideCourtsUnavailability) ?? false
self.shouldTryToFillUpCourtsAvailable = try container.decodeIfPresent(Bool.self, forKey: ._shouldTryToFillUpCourtsAvailable) ?? false self.shouldTryToFillUpCourtsAvailable = try container.decodeIfPresent(Bool.self, forKey: ._shouldTryToFillUpCourtsAvailable) ?? false
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) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.id, forKey: ._id) try container.encode(self.id, forKey: ._id)
try container.encode(self.tournament, forKey: ._tournament) try container.encode(self.tournament, forKey: ._tournament)
@ -117,7 +112,7 @@ class BaseMatchScheduler: ModelObject, Storable, Codable {
try container.encode(self.groupStageChunkCount, forKey: ._groupStageChunkCount) try container.encode(self.groupStageChunkCount, forKey: ._groupStageChunkCount)
try container.encode(self.overrideCourtsUnavailability, forKey: ._overrideCourtsUnavailability) try container.encode(self.overrideCourtsUnavailability, forKey: ._overrideCourtsUnavailability)
try container.encode(self.shouldTryToFillUpCourtsAvailable, forKey: ._shouldTryToFillUpCourtsAvailable) try container.encode(self.shouldTryToFillUpCourtsAvailable, forKey: ._shouldTryToFillUpCourtsAvailable)
try container.encode(self.storeId, forKey: ._storeId) try super.encode(to: encoder)
} }
func tournamentValue() -> Tournament? { func tournamentValue() -> Tournament? {
@ -140,8 +135,8 @@ class BaseMatchScheduler: ModelObject, Storable, Codable {
self.groupStageChunkCount = matchscheduler.groupStageChunkCount self.groupStageChunkCount = matchscheduler.groupStageChunkCount
self.overrideCourtsUnavailability = matchscheduler.overrideCourtsUnavailability self.overrideCourtsUnavailability = matchscheduler.overrideCourtsUnavailability
self.shouldTryToFillUpCourtsAvailable = matchscheduler.shouldTryToFillUpCourtsAvailable self.shouldTryToFillUpCourtsAvailable = matchscheduler.shouldTryToFillUpCourtsAvailable
self.storeId = matchscheduler.storeId
} }
static func relationships() -> [Relationship] { static func relationships() -> [Relationship] {
return [ return [
Relationship(type: Tournament.self, keyPath: \BaseMatchScheduler.tournament), Relationship(type: Tournament.self, keyPath: \BaseMatchScheduler.tournament),

@ -6,7 +6,7 @@ import LeStorage
import SwiftUI import SwiftUI
@Observable @Observable
class BaseMonthData: ModelObject, Storable, Codable { class BaseMonthData: BaseModelObject, Storable {
static func resourceName() -> String { return "month-data" } static func resourceName() -> String { return "month-data" }
static func tokenExemptedMethods() -> [HTTPMethod] { return [] } static func tokenExemptedMethods() -> [HTTPMethod] { return [] }
@ -66,7 +66,6 @@ class BaseMonthData: ModelObject, Storable, Codable {
} }
required init(from decoder: Decoder) throws { required init(from decoder: Decoder) throws {
super.init()
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId()
self.monthKey = try container.decodeIfPresent(String.self, forKey: ._monthKey) ?? "" self.monthKey = try container.decodeIfPresent(String.self, forKey: ._monthKey) ?? ""
@ -79,9 +78,10 @@ class BaseMonthData: ModelObject, Storable, Codable {
self.incompleteMode = try container.decodeIfPresent(Bool.self, forKey: ._incompleteMode) ?? false self.incompleteMode = try container.decodeIfPresent(Bool.self, forKey: ._incompleteMode) ?? false
self.dataModelIdentifier = try container.decodeIfPresent(String.self, forKey: ._dataModelIdentifier) ?? nil self.dataModelIdentifier = try container.decodeIfPresent(String.self, forKey: ._dataModelIdentifier) ?? nil
self.fileModelIdentifier = try container.decodeIfPresent(String.self, forKey: ._fileModelIdentifier) ?? nil self.fileModelIdentifier = try container.decodeIfPresent(String.self, forKey: ._fileModelIdentifier) ?? 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) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.id, forKey: ._id) try container.encode(self.id, forKey: ._id)
try container.encode(self.monthKey, forKey: ._monthKey) try container.encode(self.monthKey, forKey: ._monthKey)
@ -94,6 +94,7 @@ class BaseMonthData: ModelObject, Storable, Codable {
try container.encode(self.incompleteMode, forKey: ._incompleteMode) try container.encode(self.incompleteMode, forKey: ._incompleteMode)
try container.encode(self.dataModelIdentifier, forKey: ._dataModelIdentifier) try container.encode(self.dataModelIdentifier, forKey: ._dataModelIdentifier)
try container.encode(self.fileModelIdentifier, forKey: ._fileModelIdentifier) try container.encode(self.fileModelIdentifier, forKey: ._fileModelIdentifier)
try super.encode(to: encoder)
} }
func copy(from other: any Storable) { func copy(from other: any Storable) {
@ -110,6 +111,7 @@ class BaseMonthData: ModelObject, Storable, Codable {
self.dataModelIdentifier = monthdata.dataModelIdentifier self.dataModelIdentifier = monthdata.dataModelIdentifier
self.fileModelIdentifier = monthdata.fileModelIdentifier self.fileModelIdentifier = monthdata.fileModelIdentifier
} }
static func relationships() -> [Relationship] { static func relationships() -> [Relationship] {
return [] return []
} }

@ -6,14 +6,13 @@ import LeStorage
import SwiftUI import SwiftUI
@Observable @Observable
class BasePlayerRegistration: ModelObject, SyncedStorable, Codable { class BasePlayerRegistration: SyncedModelObject, SyncedStorable {
static func resourceName() -> String { return "player-registrations" } static func resourceName() -> String { return "player-registrations" }
static func tokenExemptedMethods() -> [HTTPMethod] { return [] } static func tokenExemptedMethods() -> [HTTPMethod] { return [] }
static func filterByStoreIdentifier() -> Bool { return true } static func filterByStoreIdentifier() -> Bool { return true }
var id: String = Store.randomId() var id: String = Store.randomId()
var lastUpdate: Date = Date()
var teamRegistration: String? = nil var teamRegistration: String? = nil
var firstName: String = "" var firstName: String = ""
var lastName: String = "" var lastName: String = ""
@ -32,11 +31,9 @@ class BasePlayerRegistration: ModelObject, SyncedStorable, Codable {
var computedRank: Int = 0 var computedRank: Int = 0
var source: PlayerDataSource? = nil var source: PlayerDataSource? = nil
var hasArrived: Bool = false var hasArrived: Bool = false
var storeId: String? = nil
init( init(
id: String = Store.randomId(), id: String = Store.randomId(),
lastUpdate: Date = Date(),
teamRegistration: String? = nil, teamRegistration: String? = nil,
firstName: String = "", firstName: String = "",
lastName: String = "", lastName: String = "",
@ -54,12 +51,10 @@ class BasePlayerRegistration: ModelObject, SyncedStorable, Codable {
birthdate: String? = nil, birthdate: String? = nil,
computedRank: Int = 0, computedRank: Int = 0,
source: PlayerDataSource? = nil, source: PlayerDataSource? = nil,
hasArrived: Bool = false, hasArrived: Bool = false
storeId: String? = nil
) { ) {
super.init() super.init()
self.id = id self.id = id
self.lastUpdate = lastUpdate
self.teamRegistration = teamRegistration self.teamRegistration = teamRegistration
self.firstName = firstName self.firstName = firstName
self.lastName = lastName self.lastName = lastName
@ -78,12 +73,10 @@ class BasePlayerRegistration: ModelObject, SyncedStorable, Codable {
self.computedRank = computedRank self.computedRank = computedRank
self.source = source self.source = source
self.hasArrived = hasArrived self.hasArrived = hasArrived
self.storeId = storeId
} }
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case _id = "id" case _id = "id"
case _lastUpdate = "lastUpdate"
case _teamRegistration = "teamRegistration" case _teamRegistration = "teamRegistration"
case _firstName = "firstName" case _firstName = "firstName"
case _lastName = "lastName" case _lastName = "lastName"
@ -102,15 +95,11 @@ class BasePlayerRegistration: ModelObject, SyncedStorable, Codable {
case _computedRank = "computedRank" case _computedRank = "computedRank"
case _source = "source" case _source = "source"
case _hasArrived = "hasArrived" case _hasArrived = "hasArrived"
case _storeId = "storeId"
} }
required init(from decoder: Decoder) throws { required init(from decoder: Decoder) throws {
super.init()
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() 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.teamRegistration = try container.decodeIfPresent(String.self, forKey: ._teamRegistration) ?? nil self.teamRegistration = try container.decodeIfPresent(String.self, forKey: ._teamRegistration) ?? nil
self.firstName = try container.decodeIfPresent(String.self, forKey: ._firstName) ?? "" self.firstName = try container.decodeIfPresent(String.self, forKey: ._firstName) ?? ""
self.lastName = try container.decodeIfPresent(String.self, forKey: ._lastName) ?? "" self.lastName = try container.decodeIfPresent(String.self, forKey: ._lastName) ?? ""
@ -129,13 +118,12 @@ class BasePlayerRegistration: ModelObject, SyncedStorable, Codable {
self.computedRank = try container.decodeIfPresent(Int.self, forKey: ._computedRank) ?? 0 self.computedRank = try container.decodeIfPresent(Int.self, forKey: ._computedRank) ?? 0
self.source = try container.decodeIfPresent(PlayerDataSource.self, forKey: ._source) ?? nil self.source = try container.decodeIfPresent(PlayerDataSource.self, forKey: ._source) ?? nil
self.hasArrived = try container.decodeIfPresent(Bool.self, forKey: ._hasArrived) ?? false self.hasArrived = try container.decodeIfPresent(Bool.self, forKey: ._hasArrived) ?? false
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) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.id, forKey: ._id) try container.encode(self.id, forKey: ._id)
try container.encode(Date.iso8601FractionalFormatter.string(from: self.lastUpdate), forKey: ._lastUpdate)
try container.encode(self.teamRegistration, forKey: ._teamRegistration) try container.encode(self.teamRegistration, forKey: ._teamRegistration)
try container.encode(self.firstName, forKey: ._firstName) try container.encode(self.firstName, forKey: ._firstName)
try container.encode(self.lastName, forKey: ._lastName) try container.encode(self.lastName, forKey: ._lastName)
@ -154,7 +142,7 @@ class BasePlayerRegistration: ModelObject, SyncedStorable, Codable {
try container.encode(self.computedRank, forKey: ._computedRank) try container.encode(self.computedRank, forKey: ._computedRank)
try container.encode(self.source, forKey: ._source) try container.encode(self.source, forKey: ._source)
try container.encode(self.hasArrived, forKey: ._hasArrived) try container.encode(self.hasArrived, forKey: ._hasArrived)
try container.encode(self.storeId, forKey: ._storeId) try super.encode(to: encoder)
} }
func teamRegistrationValue() -> TeamRegistration? { func teamRegistrationValue() -> TeamRegistration? {
@ -165,7 +153,6 @@ class BasePlayerRegistration: ModelObject, SyncedStorable, Codable {
func copy(from other: any Storable) { func copy(from other: any Storable) {
guard let playerregistration = other as? BasePlayerRegistration else { return } guard let playerregistration = other as? BasePlayerRegistration else { return }
self.id = playerregistration.id self.id = playerregistration.id
self.lastUpdate = playerregistration.lastUpdate
self.teamRegistration = playerregistration.teamRegistration self.teamRegistration = playerregistration.teamRegistration
self.firstName = playerregistration.firstName self.firstName = playerregistration.firstName
self.lastName = playerregistration.lastName self.lastName = playerregistration.lastName
@ -184,8 +171,8 @@ class BasePlayerRegistration: ModelObject, SyncedStorable, Codable {
self.computedRank = playerregistration.computedRank self.computedRank = playerregistration.computedRank
self.source = playerregistration.source self.source = playerregistration.source
self.hasArrived = playerregistration.hasArrived self.hasArrived = playerregistration.hasArrived
self.storeId = playerregistration.storeId
} }
static func relationships() -> [Relationship] { static func relationships() -> [Relationship] {
return [ return [
Relationship(type: TeamRegistration.self, keyPath: \BasePlayerRegistration.teamRegistration), Relationship(type: TeamRegistration.self, keyPath: \BasePlayerRegistration.teamRegistration),

@ -4,14 +4,13 @@
import Foundation import Foundation
import LeStorage import LeStorage
class BasePurchase: ModelObject, SyncedStorable, Codable { class BasePurchase: SyncedModelObject, SyncedStorable {
static func resourceName() -> String { return "purchases" } static func resourceName() -> String { return "purchases" }
static func tokenExemptedMethods() -> [HTTPMethod] { return [] } static func tokenExemptedMethods() -> [HTTPMethod] { return [] }
static func filterByStoreIdentifier() -> Bool { return false } static func filterByStoreIdentifier() -> Bool { return false }
var id: UInt64 = 0 var id: UInt64 = 0
var lastUpdate: Date = Date()
var user: String = "" var user: String = ""
var purchaseDate: Date = Date() var purchaseDate: Date = Date()
var productId: String = "" var productId: String = ""
@ -21,7 +20,6 @@ class BasePurchase: ModelObject, SyncedStorable, Codable {
init( init(
id: UInt64 = 0, id: UInt64 = 0,
lastUpdate: Date = Date(),
user: String = "", user: String = "",
purchaseDate: Date = Date(), purchaseDate: Date = Date(),
productId: String = "", productId: String = "",
@ -31,7 +29,6 @@ class BasePurchase: ModelObject, SyncedStorable, Codable {
) { ) {
super.init() super.init()
self.id = id self.id = id
self.lastUpdate = lastUpdate
self.user = user self.user = user
self.purchaseDate = purchaseDate self.purchaseDate = purchaseDate
self.productId = productId self.productId = productId
@ -42,7 +39,6 @@ class BasePurchase: ModelObject, SyncedStorable, Codable {
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case id = "id" case id = "id"
case lastUpdate = "lastUpdate"
case user = "user" case user = "user"
case purchaseDate = "purchaseDate" case purchaseDate = "purchaseDate"
case productId = "productId" case productId = "productId"
@ -53,29 +49,27 @@ class BasePurchase: ModelObject, SyncedStorable, Codable {
required init(from decoder: Decoder) throws { required init(from decoder: Decoder) throws {
super.init()
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decodeIfPresent(UInt64.self, forKey: .id) ?? 0 self.id = try container.decodeIfPresent(UInt64.self, forKey: .id) ?? 0
let dateString = try container.decode(String.self, forKey: .lastUpdate)
self.lastUpdate = Date.iso8601FractionalFormatter.date(from: dateString) ?? Date()
self.user = try container.decodeEncrypted(key: .user) self.user = try container.decodeEncrypted(key: .user)
self.purchaseDate = try container.decodeIfPresent(Date.self, forKey: .purchaseDate) ?? Date() self.purchaseDate = try container.decodeIfPresent(Date.self, forKey: .purchaseDate) ?? Date()
self.productId = try container.decodeIfPresent(String.self, forKey: .productId) ?? "" self.productId = try container.decodeIfPresent(String.self, forKey: .productId) ?? ""
self.quantity = try container.decodeIfPresent(Int.self, forKey: .quantity) ?? nil self.quantity = try container.decodeIfPresent(Int.self, forKey: .quantity) ?? nil
self.revocationDate = try container.decodeIfPresent(Date.self, forKey: .revocationDate) ?? nil self.revocationDate = try container.decodeIfPresent(Date.self, forKey: .revocationDate) ?? nil
self.expirationDate = try container.decodeIfPresent(Date.self, forKey: .expirationDate) ?? nil self.expirationDate = try container.decodeIfPresent(Date.self, forKey: .expirationDate) ?? 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) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.id, forKey: .id) try container.encode(self.id, forKey: .id)
try container.encode(Date.iso8601FractionalFormatter.string(from: self.lastUpdate), forKey: .lastUpdate)
try container.encodeAndEncryptIfPresent(self.user.data(using: .utf8), forKey: .user) try container.encodeAndEncryptIfPresent(self.user.data(using: .utf8), forKey: .user)
try container.encode(self.purchaseDate, forKey: .purchaseDate) try container.encode(self.purchaseDate, forKey: .purchaseDate)
try container.encode(self.productId, forKey: .productId) try container.encode(self.productId, forKey: .productId)
try container.encode(self.quantity, forKey: .quantity) try container.encode(self.quantity, forKey: .quantity)
try container.encode(self.revocationDate, forKey: .revocationDate) try container.encode(self.revocationDate, forKey: .revocationDate)
try container.encode(self.expirationDate, forKey: .expirationDate) try container.encode(self.expirationDate, forKey: .expirationDate)
try super.encode(to: encoder)
} }
func userValue() -> CustomUser? { func userValue() -> CustomUser? {
@ -85,7 +79,6 @@ class BasePurchase: ModelObject, SyncedStorable, Codable {
func copy(from other: any Storable) { func copy(from other: any Storable) {
guard let purchase = other as? BasePurchase else { return } guard let purchase = other as? BasePurchase else { return }
self.id = purchase.id self.id = purchase.id
self.lastUpdate = purchase.lastUpdate
self.user = purchase.user self.user = purchase.user
self.purchaseDate = purchase.purchaseDate self.purchaseDate = purchase.purchaseDate
self.productId = purchase.productId self.productId = purchase.productId
@ -93,6 +86,7 @@ class BasePurchase: ModelObject, SyncedStorable, Codable {
self.revocationDate = purchase.revocationDate self.revocationDate = purchase.revocationDate
self.expirationDate = purchase.expirationDate self.expirationDate = purchase.expirationDate
} }
static func relationships() -> [Relationship] { static func relationships() -> [Relationship] {
return [ return [
Relationship(type: CustomUser.self, keyPath: \BasePurchase.user), Relationship(type: CustomUser.self, keyPath: \BasePurchase.user),

@ -6,14 +6,13 @@ import LeStorage
import SwiftUI import SwiftUI
@Observable @Observable
class BaseRound: ModelObject, SyncedStorable, Codable { class BaseRound: SyncedModelObject, SyncedStorable {
static func resourceName() -> String { return "rounds" } static func resourceName() -> String { return "rounds" }
static func tokenExemptedMethods() -> [HTTPMethod] { return [] } static func tokenExemptedMethods() -> [HTTPMethod] { return [] }
static func filterByStoreIdentifier() -> Bool { return true } static func filterByStoreIdentifier() -> Bool { return true }
var id: String = Store.randomId() var id: String = Store.randomId()
var lastUpdate: Date = Date()
var tournament: String = "" var tournament: String = ""
var index: Int = 0 var index: Int = 0
var parent: String? = nil var parent: String? = nil
@ -21,23 +20,19 @@ class BaseRound: ModelObject, SyncedStorable, Codable {
var startDate: Date? = nil var startDate: Date? = nil
var groupStageLoserBracket: Bool = false var groupStageLoserBracket: Bool = false
var loserBracketMode: LoserBracketMode = .automatic var loserBracketMode: LoserBracketMode = .automatic
var storeId: String? = nil
init( init(
id: String = Store.randomId(), id: String = Store.randomId(),
lastUpdate: Date = Date(),
tournament: String = "", tournament: String = "",
index: Int = 0, index: Int = 0,
parent: String? = nil, parent: String? = nil,
format: MatchFormat? = nil, format: MatchFormat? = nil,
startDate: Date? = nil, startDate: Date? = nil,
groupStageLoserBracket: Bool = false, groupStageLoserBracket: Bool = false,
loserBracketMode: LoserBracketMode = .automatic, loserBracketMode: LoserBracketMode = .automatic
storeId: String? = nil
) { ) {
super.init() super.init()
self.id = id self.id = id
self.lastUpdate = lastUpdate
self.tournament = tournament self.tournament = tournament
self.index = index self.index = index
self.parent = parent self.parent = parent
@ -45,12 +40,10 @@ class BaseRound: ModelObject, SyncedStorable, Codable {
self.startDate = startDate self.startDate = startDate
self.groupStageLoserBracket = groupStageLoserBracket self.groupStageLoserBracket = groupStageLoserBracket
self.loserBracketMode = loserBracketMode self.loserBracketMode = loserBracketMode
self.storeId = storeId
} }
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case _id = "id" case _id = "id"
case _lastUpdate = "lastUpdate"
case _tournament = "tournament" case _tournament = "tournament"
case _index = "index" case _index = "index"
case _parent = "parent" case _parent = "parent"
@ -58,15 +51,11 @@ class BaseRound: ModelObject, SyncedStorable, Codable {
case _startDate = "startDate" case _startDate = "startDate"
case _groupStageLoserBracket = "groupStageLoserBracket" case _groupStageLoserBracket = "groupStageLoserBracket"
case _loserBracketMode = "loserBracketMode" case _loserBracketMode = "loserBracketMode"
case _storeId = "storeId"
} }
required init(from decoder: Decoder) throws { required init(from decoder: Decoder) throws {
super.init()
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() 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.tournament = try container.decodeIfPresent(String.self, forKey: ._tournament) ?? ""
self.index = try container.decodeIfPresent(Int.self, forKey: ._index) ?? 0 self.index = try container.decodeIfPresent(Int.self, forKey: ._index) ?? 0
self.parent = try container.decodeIfPresent(String.self, forKey: ._parent) ?? nil self.parent = try container.decodeIfPresent(String.self, forKey: ._parent) ?? nil
@ -74,13 +63,12 @@ class BaseRound: ModelObject, SyncedStorable, Codable {
self.startDate = try container.decodeIfPresent(Date.self, forKey: ._startDate) ?? nil self.startDate = try container.decodeIfPresent(Date.self, forKey: ._startDate) ?? nil
self.groupStageLoserBracket = try container.decodeIfPresent(Bool.self, forKey: ._groupStageLoserBracket) ?? false self.groupStageLoserBracket = try container.decodeIfPresent(Bool.self, forKey: ._groupStageLoserBracket) ?? false
self.loserBracketMode = try container.decodeIfPresent(LoserBracketMode.self, forKey: ._loserBracketMode) ?? .automatic self.loserBracketMode = try container.decodeIfPresent(LoserBracketMode.self, forKey: ._loserBracketMode) ?? .automatic
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) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.id, forKey: ._id) 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.tournament, forKey: ._tournament)
try container.encode(self.index, forKey: ._index) try container.encode(self.index, forKey: ._index)
try container.encode(self.parent, forKey: ._parent) try container.encode(self.parent, forKey: ._parent)
@ -88,7 +76,7 @@ class BaseRound: ModelObject, SyncedStorable, Codable {
try container.encode(self.startDate, forKey: ._startDate) try container.encode(self.startDate, forKey: ._startDate)
try container.encode(self.groupStageLoserBracket, forKey: ._groupStageLoserBracket) try container.encode(self.groupStageLoserBracket, forKey: ._groupStageLoserBracket)
try container.encode(self.loserBracketMode, forKey: ._loserBracketMode) try container.encode(self.loserBracketMode, forKey: ._loserBracketMode)
try container.encode(self.storeId, forKey: ._storeId) try super.encode(to: encoder)
} }
func tournamentValue() -> Tournament? { func tournamentValue() -> Tournament? {
@ -98,7 +86,6 @@ class BaseRound: ModelObject, SyncedStorable, Codable {
func copy(from other: any Storable) { func copy(from other: any Storable) {
guard let round = other as? BaseRound else { return } guard let round = other as? BaseRound else { return }
self.id = round.id self.id = round.id
self.lastUpdate = round.lastUpdate
self.tournament = round.tournament self.tournament = round.tournament
self.index = round.index self.index = round.index
self.parent = round.parent self.parent = round.parent
@ -106,8 +93,8 @@ class BaseRound: ModelObject, SyncedStorable, Codable {
self.startDate = round.startDate self.startDate = round.startDate
self.groupStageLoserBracket = round.groupStageLoserBracket self.groupStageLoserBracket = round.groupStageLoserBracket
self.loserBracketMode = round.loserBracketMode self.loserBracketMode = round.loserBracketMode
self.storeId = round.storeId
} }
static func relationships() -> [Relationship] { static func relationships() -> [Relationship] {
return [ return [
Relationship(type: Tournament.self, keyPath: \BaseRound.tournament), Relationship(type: Tournament.self, keyPath: \BaseRound.tournament),

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

@ -6,77 +6,65 @@ import LeStorage
import SwiftUI import SwiftUI
@Observable @Observable
class BaseTeamScore: ModelObject, SyncedStorable, Codable { class BaseTeamScore: SyncedModelObject, SyncedStorable {
static func resourceName() -> String { return "team-scores" } static func resourceName() -> String { return "team-scores" }
static func tokenExemptedMethods() -> [HTTPMethod] { return [] } static func tokenExemptedMethods() -> [HTTPMethod] { return [] }
static func filterByStoreIdentifier() -> Bool { return true } static func filterByStoreIdentifier() -> Bool { return true }
var id: String = Store.randomId() var id: String = Store.randomId()
var lastUpdate: Date = Date()
var match: String = "" var match: String = ""
var teamRegistration: String? = nil var teamRegistration: String? = nil
var score: String? = nil var score: String? = nil
var walkOut: Int? = nil var walkOut: Int? = nil
var luckyLoser: Int? = nil var luckyLoser: Int? = nil
var storeId: String? = nil
init( init(
id: String = Store.randomId(), id: String = Store.randomId(),
lastUpdate: Date = Date(),
match: String = "", match: String = "",
teamRegistration: String? = nil, teamRegistration: String? = nil,
score: String? = nil, score: String? = nil,
walkOut: Int? = nil, walkOut: Int? = nil,
luckyLoser: Int? = nil, luckyLoser: Int? = nil
storeId: String? = nil
) { ) {
super.init() super.init()
self.id = id self.id = id
self.lastUpdate = lastUpdate
self.match = match self.match = match
self.teamRegistration = teamRegistration self.teamRegistration = teamRegistration
self.score = score self.score = score
self.walkOut = walkOut self.walkOut = walkOut
self.luckyLoser = luckyLoser self.luckyLoser = luckyLoser
self.storeId = storeId
} }
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case _id = "id" case _id = "id"
case _lastUpdate = "lastUpdate"
case _match = "match" case _match = "match"
case _teamRegistration = "teamRegistration" case _teamRegistration = "teamRegistration"
case _score = "score" case _score = "score"
case _walkOut = "walkOut" case _walkOut = "walkOut"
case _luckyLoser = "luckyLoser" case _luckyLoser = "luckyLoser"
case _storeId = "storeId"
} }
required init(from decoder: Decoder) throws { required init(from decoder: Decoder) throws {
super.init()
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() 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.match = try container.decodeIfPresent(String.self, forKey: ._match) ?? "" self.match = try container.decodeIfPresent(String.self, forKey: ._match) ?? ""
self.teamRegistration = try container.decodeIfPresent(String.self, forKey: ._teamRegistration) ?? nil self.teamRegistration = try container.decodeIfPresent(String.self, forKey: ._teamRegistration) ?? nil
self.score = try container.decodeIfPresent(String.self, forKey: ._score) ?? nil self.score = try container.decodeIfPresent(String.self, forKey: ._score) ?? nil
self.walkOut = try container.decodeIfPresent(Int.self, forKey: ._walkOut) ?? nil self.walkOut = try container.decodeIfPresent(Int.self, forKey: ._walkOut) ?? nil
self.luckyLoser = try container.decodeIfPresent(Int.self, forKey: ._luckyLoser) ?? nil self.luckyLoser = try container.decodeIfPresent(Int.self, forKey: ._luckyLoser) ?? 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) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.id, forKey: ._id) try container.encode(self.id, forKey: ._id)
try container.encode(Date.iso8601FractionalFormatter.string(from: self.lastUpdate), forKey: ._lastUpdate)
try container.encode(self.match, forKey: ._match) try container.encode(self.match, forKey: ._match)
try container.encode(self.teamRegistration, forKey: ._teamRegistration) try container.encode(self.teamRegistration, forKey: ._teamRegistration)
try container.encode(self.score, forKey: ._score) try container.encode(self.score, forKey: ._score)
try container.encode(self.walkOut, forKey: ._walkOut) try container.encode(self.walkOut, forKey: ._walkOut)
try container.encode(self.luckyLoser, forKey: ._luckyLoser) try container.encode(self.luckyLoser, forKey: ._luckyLoser)
try container.encode(self.storeId, forKey: ._storeId) try super.encode(to: encoder)
} }
func matchValue() -> Match? { func matchValue() -> Match? {
@ -91,14 +79,13 @@ class BaseTeamScore: ModelObject, SyncedStorable, Codable {
func copy(from other: any Storable) { func copy(from other: any Storable) {
guard let teamscore = other as? BaseTeamScore else { return } guard let teamscore = other as? BaseTeamScore else { return }
self.id = teamscore.id self.id = teamscore.id
self.lastUpdate = teamscore.lastUpdate
self.match = teamscore.match self.match = teamscore.match
self.teamRegistration = teamscore.teamRegistration self.teamRegistration = teamscore.teamRegistration
self.score = teamscore.score self.score = teamscore.score
self.walkOut = teamscore.walkOut self.walkOut = teamscore.walkOut
self.luckyLoser = teamscore.luckyLoser self.luckyLoser = teamscore.luckyLoser
self.storeId = teamscore.storeId
} }
static func relationships() -> [Relationship] { static func relationships() -> [Relationship] {
return [ return [
Relationship(type: Match.self, keyPath: \BaseTeamScore.match), Relationship(type: Match.self, keyPath: \BaseTeamScore.match),

@ -6,14 +6,13 @@ import LeStorage
import SwiftUI import SwiftUI
@Observable @Observable
class BaseTournament: ModelObject, SyncedStorable, Codable { class BaseTournament: SyncedModelObject, SyncedStorable {
static func resourceName() -> String { return "tournaments" } static func resourceName() -> String { return "tournaments" }
static func tokenExemptedMethods() -> [HTTPMethod] { return [] } static func tokenExemptedMethods() -> [HTTPMethod] { return [] }
static func filterByStoreIdentifier() -> Bool { return false } static func filterByStoreIdentifier() -> Bool { return false }
var id: String = Store.randomId() var id: String = Store.randomId()
var lastUpdate: Date = Date()
var event: String? = nil var event: String? = nil
var name: String? = nil var name: String? = nil
var startDate: Date = Date() var startDate: Date = Date()
@ -57,7 +56,6 @@ class BaseTournament: ModelObject, SyncedStorable, Codable {
init( init(
id: String = Store.randomId(), id: String = Store.randomId(),
lastUpdate: Date = Date(),
event: String? = nil, event: String? = nil,
name: String? = nil, name: String? = nil,
startDate: Date = Date(), startDate: Date = Date(),
@ -101,7 +99,6 @@ class BaseTournament: ModelObject, SyncedStorable, Codable {
) { ) {
super.init() super.init()
self.id = id self.id = id
self.lastUpdate = lastUpdate
self.event = event self.event = event
self.name = name self.name = name
self.startDate = startDate self.startDate = startDate
@ -146,7 +143,6 @@ class BaseTournament: ModelObject, SyncedStorable, Codable {
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case _id = "id" case _id = "id"
case _lastUpdate = "lastUpdate"
case _event = "event" case _event = "event"
case _name = "name" case _name = "name"
case _startDate = "startDate" case _startDate = "startDate"
@ -251,11 +247,8 @@ class BaseTournament: ModelObject, SyncedStorable, Codable {
} }
required init(from decoder: Decoder) throws { required init(from decoder: Decoder) throws {
super.init()
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() 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.event = try container.decodeIfPresent(String.self, forKey: ._event) ?? nil self.event = try container.decodeIfPresent(String.self, forKey: ._event) ?? nil
self.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? nil self.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? nil
self.startDate = try container.decodeIfPresent(Date.self, forKey: ._startDate) ?? Date() self.startDate = try container.decodeIfPresent(Date.self, forKey: ._startDate) ?? Date()
@ -296,12 +289,12 @@ class BaseTournament: ModelObject, SyncedStorable, Codable {
self.hidePointsEarned = try container.decodeIfPresent(Bool.self, forKey: ._hidePointsEarned) ?? false self.hidePointsEarned = try container.decodeIfPresent(Bool.self, forKey: ._hidePointsEarned) ?? false
self.publishRankings = try container.decodeIfPresent(Bool.self, forKey: ._publishRankings) ?? false self.publishRankings = try container.decodeIfPresent(Bool.self, forKey: ._publishRankings) ?? false
self.loserBracketMode = try container.decodeIfPresent(LoserBracketMode.self, forKey: ._loserBracketMode) ?? .automatic self.loserBracketMode = try container.decodeIfPresent(LoserBracketMode.self, forKey: ._loserBracketMode) ?? .automatic
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) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.id, forKey: ._id) try container.encode(self.id, forKey: ._id)
try container.encode(Date.iso8601FractionalFormatter.string(from: self.lastUpdate), forKey: ._lastUpdate)
try container.encode(self.event, forKey: ._event) try container.encode(self.event, forKey: ._event)
try container.encode(self.name, forKey: ._name) try container.encode(self.name, forKey: ._name)
try container.encode(self.startDate, forKey: ._startDate) try container.encode(self.startDate, forKey: ._startDate)
@ -342,6 +335,7 @@ class BaseTournament: ModelObject, SyncedStorable, Codable {
try container.encode(self.hidePointsEarned, forKey: ._hidePointsEarned) try container.encode(self.hidePointsEarned, forKey: ._hidePointsEarned)
try container.encode(self.publishRankings, forKey: ._publishRankings) try container.encode(self.publishRankings, forKey: ._publishRankings)
try container.encode(self.loserBracketMode, forKey: ._loserBracketMode) try container.encode(self.loserBracketMode, forKey: ._loserBracketMode)
try super.encode(to: encoder)
} }
func eventValue() -> Event? { func eventValue() -> Event? {
@ -352,7 +346,6 @@ class BaseTournament: ModelObject, SyncedStorable, Codable {
func copy(from other: any Storable) { func copy(from other: any Storable) {
guard let tournament = other as? BaseTournament else { return } guard let tournament = other as? BaseTournament else { return }
self.id = tournament.id self.id = tournament.id
self.lastUpdate = tournament.lastUpdate
self.event = tournament.event self.event = tournament.event
self.name = tournament.name self.name = tournament.name
self.startDate = tournament.startDate self.startDate = tournament.startDate
@ -394,6 +387,7 @@ class BaseTournament: ModelObject, SyncedStorable, Codable {
self.publishRankings = tournament.publishRankings self.publishRankings = tournament.publishRankings
self.loserBracketMode = tournament.loserBracketMode self.loserBracketMode = tournament.loserBracketMode
} }
static func relationships() -> [Relationship] { static func relationships() -> [Relationship] {
return [ return [
Relationship(type: Event.self, keyPath: \BaseTournament.event), Relationship(type: Event.self, keyPath: \BaseTournament.event),

@ -10,11 +10,6 @@
"type": "String", "type": "String",
"defaultValue": "Store.randomId()" "defaultValue": "Store.randomId()"
}, },
{
"name": "lastUpdate",
"type": "Date",
"option": "fractional"
},
{ {
"name": "creator", "name": "creator",
"type": "String", "type": "String",

@ -10,11 +10,6 @@
"type": "String", "type": "String",
"defaultValue": "Store.randomId()" "defaultValue": "Store.randomId()"
}, },
{
"name": "lastUpdate",
"type": "Date",
"option": "fractional"
},
{ {
"name": "index", "name": "index",
"type": "Int" "type": "Int"

@ -13,11 +13,6 @@
"type": "String", "type": "String",
"defaultValue": "Store.randomId()" "defaultValue": "Store.randomId()"
}, },
{
"name": "lastUpdate",
"type": "Date",
"option": "fractional"
},
{ {
"name": "username", "name": "username",
"type": "String" "type": "String"

@ -10,11 +10,6 @@
"type": "String", "type": "String",
"defaultValue": "Store.randomId()" "defaultValue": "Store.randomId()"
}, },
{
"name": "lastUpdate",
"type": "Date",
"option": "fractional"
},
{ {
"name": "event", "name": "event",
"type": "String" "type": "String"

@ -10,11 +10,6 @@
"type": "String", "type": "String",
"defaultValue": "Store.randomId()" "defaultValue": "Store.randomId()"
}, },
{
"name": "lastUpdate",
"type": "Date",
"option": "fractional"
},
{ {
"name": "creator", "name": "creator",
"type": "String", "type": "String",

@ -10,11 +10,6 @@
"type": "String", "type": "String",
"defaultValue": "Store.randomId()" "defaultValue": "Store.randomId()"
}, },
{
"name": "lastUpdate",
"type": "Date",
"option": "fractional"
},
{ {
"name": "tournament", "name": "tournament",
"type": "String", "type": "String",
@ -50,12 +45,6 @@
"name": "step", "name": "step",
"type": "Int", "type": "Int",
"defaultValue": "0" "defaultValue": "0"
},
{
"name": "storeId",
"type": "String",
"optional": true,
"defaultValue": "nil"
} }
], ],
"tokenExemptedMethods": [], "tokenExemptedMethods": [],

@ -12,11 +12,6 @@
"type": "String", "type": "String",
"defaultValue": "Store.randomId()" "defaultValue": "Store.randomId()"
}, },
{
"name": "lastUpdate",
"type": "Date",
"option": "fractional"
},
{ {
"name": "round", "name": "round",
"type": "String", "type": "String",
@ -82,11 +77,6 @@
"name": "confirmed", "name": "confirmed",
"type": "Bool", "type": "Bool",
"defaultValue": "false" "defaultValue": "false"
},
{
"name": "storeId",
"type": "String",
"optional": true
} }
] ]
} }

@ -68,11 +68,6 @@
"name": "shouldTryToFillUpCourtsAvailable", "name": "shouldTryToFillUpCourtsAvailable",
"type": "Bool", "type": "Bool",
"defaultValue": "false" "defaultValue": "false"
},
{
"name": "storeId",
"type": "String",
"optional": true
} }
] ]
} }

@ -13,11 +13,6 @@
"type": "String", "type": "String",
"defaultValue": "Store.randomId()" "defaultValue": "Store.randomId()"
}, },
{
"name": "lastUpdate",
"type": "Date",
"option": "fractional"
},
{ {
"name": "teamRegistration", "name": "teamRegistration",
"type": "String", "type": "String",
@ -106,12 +101,6 @@
"name": "hasArrived", "name": "hasArrived",
"type": "Bool", "type": "Bool",
"defaultValue": "false" "defaultValue": "false"
},
{
"name": "storeId",
"type": "String",
"optional": true,
"defaultValue": "nil"
} }
] ]
} }

@ -9,11 +9,6 @@
"type": "UInt64", "type": "UInt64",
"defaultValue": "0" "defaultValue": "0"
}, },
{
"name": "lastUpdate",
"type": "Date",
"option": "fractional"
},
{ {
"name": "user", "name": "user",
"type": "String", "type": "String",

@ -13,11 +13,6 @@
"type": "String", "type": "String",
"defaultValue": "Store.randomId()" "defaultValue": "Store.randomId()"
}, },
{
"name": "lastUpdate",
"type": "Date",
"option": "fractional"
},
{ {
"name": "tournament", "name": "tournament",
"type": "String", "type": "String",
@ -52,12 +47,6 @@
"name": "loserBracketMode", "name": "loserBracketMode",
"type": "LoserBracketMode", "type": "LoserBracketMode",
"defaultValue": ".automatic" "defaultValue": ".automatic"
},
{
"name": "storeId",
"type": "String",
"optional": true,
"defaultValue": "nil"
} }
] ]
} }

@ -13,11 +13,6 @@
"type": "String", "type": "String",
"defaultValue": "Store.randomId()" "defaultValue": "Store.randomId()"
}, },
{
"name": "lastUpdate",
"type": "Date",
"option": "fractional"
},
{ {
"name": "tournament", "name": "tournament",
"type": "String" "type": "String"
@ -117,12 +112,6 @@
"name": "pointsEarned", "name": "pointsEarned",
"type": "Int", "type": "Int",
"optional": true "optional": true
},
{
"name": "storeId",
"type": "String",
"optional": true,
"defaultValue": "nil"
} }
] ]
} }

@ -13,11 +13,6 @@
"type": "String", "type": "String",
"defaultValue": "Store.randomId()" "defaultValue": "Store.randomId()"
}, },
{
"name": "lastUpdate",
"type": "Date",
"option": "fractional"
},
{ {
"name": "match", "name": "match",
"type": "String", "type": "String",
@ -43,12 +38,6 @@
"name": "luckyLoser", "name": "luckyLoser",
"type": "Int", "type": "Int",
"optional": true "optional": true
},
{
"name": "storeId",
"type": "String",
"optional": true,
"defaultValue": "nil"
} }
] ]
} }

@ -13,11 +13,6 @@
"type": "String", "type": "String",
"defaultValue": "Store.randomId()" "defaultValue": "Store.randomId()"
}, },
{
"name": "lastUpdate",
"type": "Date",
"option": "fractional"
},
{ {
"name": "event", "name": "event",
"type": "String", "type": "String",

@ -39,7 +39,8 @@ class SwiftModelGenerator:
if is_observable: if is_observable:
lines.append("@Observable") lines.append("@Observable")
protocol = "SyncedStorable" if is_sync else "Storable" protocol = "SyncedStorable" if is_sync else "Storable"
lines.append(f"class Base{model_name}: ModelObject, {protocol}, Codable {{") base_class = "SyncedModelObject" if is_sync else "BaseModelObject"
lines.append(f"class Base{model_name}: {base_class}, {protocol} {{")
lines.append("") lines.append("")
# Add SyncedStorable protocol requirements # Add SyncedStorable protocol requirements
@ -61,7 +62,7 @@ class SwiftModelGenerator:
lines.append("") lines.append("")
# CodingKeys # CodingKeys
lines.extend(self._generate_coding_keys(properties, is_observable)) lines.extend(self._generate_coding_keys(properties, is_observable, is_sync))
lines.append("") lines.append("")
# Encryption methods # Encryption methods
@ -71,9 +72,9 @@ class SwiftModelGenerator:
lines.append("") lines.append("")
# Codable implementation # Codable implementation
lines.extend(self._generate_decoder(model_name, properties, is_observable)) lines.extend(self._generate_decoder(model_name, properties, is_observable, is_sync))
lines.append("") lines.append("")
lines.extend(self._generate_encoder(properties, is_observable)) lines.extend(self._generate_encoder(properties, is_observable, is_sync))
lines.append("") lines.append("")
# Foreign Key convenience # Foreign Key convenience
@ -166,13 +167,14 @@ class SwiftModelGenerator:
lines.extend([" }", ""]) # Close the method and add a blank line lines.extend([" }", ""]) # Close the method and add a blank line
return lines return lines
def _generate_coding_keys(self, properties: List[Dict[str, Any]], is_observable: bool) -> List[str]: def _generate_coding_keys(self, properties: List[Dict[str, Any]], is_observable: bool, is_sync: bool = False) -> List[str]:
lines = [" enum CodingKeys: String, CodingKey {"] lines = [" enum CodingKeys: String, CodingKey {"]
for prop in properties: for prop in properties:
name = prop['name'] name = prop['name']
# Add underscore prefix to case name if observable, but keep the string value without underscore # Add underscore prefix to case name if observable, but keep the string value without underscore
case_name = f"_{name}" if is_observable else name case_name = f"_{name}" if is_observable else name
lines.append(f" case {case_name} = \"{name}\"") lines.append(f" case {case_name} = \"{name}\"")
lines.append(" }") lines.append(" }")
return lines return lines
@ -250,9 +252,8 @@ class SwiftModelGenerator:
]) ])
return lines return lines
def _generate_decoder(self, model_name: str, properties: List[Dict[str, Any]], is_observable: bool) -> List[str]: def _generate_decoder(self, model_name: str, properties: List[Dict[str, Any]], is_observable: bool, is_sync: bool = False) -> List[str]:
lines = [" required init(from decoder: Decoder) throws {", lines = [" required init(from decoder: Decoder) throws {",
" super.init()",
" let container = try decoder.container(keyedBy: CodingKeys.self)"] " let container = try decoder.container(keyedBy: CodingKeys.self)"]
for prop in properties: for prop in properties:
@ -288,11 +289,14 @@ class SwiftModelGenerator:
lines.append(f" self.{name} = Date.iso8601FractionalFormatter.date(from: dateString) ?? {default_value}") lines.append(f" self.{name} = Date.iso8601FractionalFormatter.date(from: dateString) ?? {default_value}")
else: else:
lines.append(f" self.{name} = try container.decodeIfPresent({type_name}.self, forKey: .{case_ref}) ?? {default_value}") lines.append(f" self.{name} = try container.decodeIfPresent({type_name}.self, forKey: .{case_ref}) ?? {default_value}")
lines.append(" try super.init(from: decoder)")
lines.append(" }") lines.append(" }")
return lines return lines
def _generate_encoder(self, properties: List[Dict[str, Any]], is_observable: bool) -> List[str]: def _generate_encoder(self, properties: List[Dict[str, Any]], is_observable: bool, is_sync: bool = False) -> List[str]:
lines = [" func encode(to encoder: Encoder) throws {", lines = [" override func encode(to encoder: Encoder) throws {",
" var container = encoder.container(keyedBy: CodingKeys.self)"] " var container = encoder.container(keyedBy: CodingKeys.self)"]
for prop in properties: for prop in properties:
@ -326,6 +330,7 @@ class SwiftModelGenerator:
else: else:
lines.append(f" try container.encode(self.{name}, forKey: .{case_ref})") lines.append(f" try container.encode(self.{name}, forKey: .{case_ref})")
lines.append(" try super.encode(to: encoder)")
lines.append(" }") lines.append(" }")
return lines return lines

@ -45,7 +45,7 @@ final class TeamRegistration: BaseTeamRegistration, SideStorable {
init(tournament: String, groupStage: String? = nil, registrationDate: Date? = nil, callDate: Date? = nil, bracketPosition: Int? = nil, groupStagePosition: Int? = nil, comment: String? = nil, source: String? = nil, sourceValue: String? = nil, logo: String? = nil, name: String? = nil, walkOut: Bool = false, wildCardBracket: Bool = false, wildCardGroupStage: Bool = false, weight: Int = 0, lockedWeight: Int? = nil, confirmationDate: Date? = nil, qualified: Bool = false) { init(tournament: String, groupStage: String? = nil, registrationDate: Date? = nil, callDate: Date? = nil, bracketPosition: Int? = nil, groupStagePosition: Int? = nil, comment: String? = nil, source: String? = nil, sourceValue: String? = nil, logo: String? = nil, name: String? = nil, walkOut: Bool = false, wildCardBracket: Bool = false, wildCardGroupStage: Bool = false, weight: Int = 0, lockedWeight: Int? = nil, confirmationDate: Date? = nil, qualified: Bool = false) {
super.init(storeId: tournament) super.init()
// self.storeId = tournament // self.storeId = tournament
self.tournament = tournament self.tournament = tournament

@ -61,8 +61,6 @@ final class Tournament: BaseTournament {
// var publishRankings: Bool = false // var publishRankings: Bool = false
// var loserBracketMode: LoserBracketMode = .automatic // var loserBracketMode: LoserBracketMode = .automatic
var storeId: String? { return nil }
@ObservationIgnored @ObservationIgnored
var navigationPath: [Screen] = [] var navigationPath: [Screen] = []

@ -24,8 +24,6 @@ class Purchase: BasePurchase {
// var revocationDate: Date? = nil // var revocationDate: Date? = nil
// var expirationDate: Date? = nil // var expirationDate: Date? = nil
var storeId: String? { return nil }
init(user: String, transactionId: UInt64, purchaseDate: Date, productId: String, quantity: Int? = nil, revocationDate: Date? = nil, expirationDate: Date? = nil) { init(user: String, transactionId: UInt64, purchaseDate: Date, productId: String, quantity: Int? = nil, revocationDate: Date? = nil, expirationDate: Date? = nil) {
super.init(id: transactionId, user: user, purchaseDate: purchaseDate, productId: productId, quantity: quantity, revocationDate: revocationDate, expirationDate: expirationDate) super.init(id: transactionId, user: user, purchaseDate: purchaseDate, productId: productId, quantity: quantity, revocationDate: revocationDate, expirationDate: expirationDate)

Loading…
Cancel
Save