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. 18
      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. 27
      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 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) {
super.init()

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

@ -48,8 +48,6 @@ class CustomUser: BaseCustomUser, UserBase {
//
// var deviceId: String?
var storeId: String? { return nil }
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)

@ -12,8 +12,6 @@ import SwiftUI
@Observable
final class Event: BaseEvent {
var storeId: String? { return 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)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -24,8 +24,6 @@ class Purchase: BasePurchase {
// var revocationDate: 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) {
super.init(id: transactionId, user: user, purchaseDate: purchaseDate, productId: productId, quantity: quantity, revocationDate: revocationDate, expirationDate: expirationDate)

Loading…
Cancel
Save