Regeneration of classes to handle relationships

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

@ -81,7 +81,8 @@ class BaseClub: ModelObject, SyncedStorable, Codable {
super.init() 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.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() 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) ?? ""
@ -99,7 +100,7 @@ class BaseClub: ModelObject, SyncedStorable, Codable {
func encode(to encoder: Encoder) throws { 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.lastUpdate, forKey: ._lastUpdate) 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)
@ -136,4 +137,10 @@ 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] {
return [
Relationship(type: CustomUser.self, keyPath: \BaseClub.creator),
]
}
} }

@ -53,7 +53,8 @@ class BaseCourt: ModelObject, SyncedStorable, Codable {
super.init() 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.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() 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
@ -64,7 +65,7 @@ class BaseCourt: ModelObject, SyncedStorable, Codable {
func encode(to encoder: Encoder) throws { 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.lastUpdate, forKey: ._lastUpdate) 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)
@ -86,4 +87,10 @@ class BaseCourt: ModelObject, SyncedStorable, Codable {
self.exitAllowed = court.exitAllowed self.exitAllowed = court.exitAllowed
self.indoor = court.indoor self.indoor = court.indoor
} }
static func relationships() -> [Relationship] {
return [
Relationship(type: Club.self, keyPath: \BaseCourt.club),
]
}
} }

@ -117,7 +117,8 @@ class BaseCustomUser: ModelObject, SyncedStorable, Codable {
super.init() 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.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() 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) ?? []
@ -144,7 +145,7 @@ class BaseCustomUser: ModelObject, SyncedStorable, Codable {
func encode(to encoder: Encoder) throws { 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.lastUpdate, forKey: ._lastUpdate) 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)
@ -194,4 +195,8 @@ 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] {
return []
}
} }

@ -49,7 +49,8 @@ class BaseDateInterval: ModelObject, SyncedStorable, Codable {
super.init() 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.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() 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()
@ -59,7 +60,7 @@ class BaseDateInterval: ModelObject, SyncedStorable, Codable {
func encode(to encoder: Encoder) throws { 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.lastUpdate, forKey: ._lastUpdate) 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)
@ -75,4 +76,8 @@ class BaseDateInterval: ModelObject, SyncedStorable, Codable {
self.startDate = dateinterval.startDate self.startDate = dateinterval.startDate
self.endDate = dateinterval.endDate self.endDate = dateinterval.endDate
} }
static func relationships() -> [Relationship] {
return []
}
} }

@ -53,7 +53,8 @@ class BaseEvent: ModelObject, SyncedStorable, Codable {
super.init() 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.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() 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()
@ -64,7 +65,7 @@ class BaseEvent: ModelObject, SyncedStorable, Codable {
func encode(to encoder: Encoder) throws { 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.lastUpdate, forKey: ._lastUpdate) 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)
@ -92,4 +93,11 @@ class BaseEvent: ModelObject, SyncedStorable, Codable {
self.name = event.name self.name = event.name
self.tenupId = event.tenupId self.tenupId = event.tenupId
} }
static func relationships() -> [Relationship] {
return [
Relationship(type: CustomUser.self, keyPath: \BaseEvent.creator),
Relationship(type: Club.self, keyPath: \BaseEvent.club),
]
}
} }

@ -65,7 +65,8 @@ class BaseGroupStage: ModelObject, SyncedStorable, Codable {
super.init() 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.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() 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
@ -79,7 +80,7 @@ class BaseGroupStage: ModelObject, SyncedStorable, Codable {
func encode(to encoder: Encoder) throws { 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.lastUpdate, forKey: ._lastUpdate) 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)
@ -107,4 +108,10 @@ class BaseGroupStage: ModelObject, SyncedStorable, Codable {
self.step = groupstage.step self.step = groupstage.step
self.storeId = groupstage.storeId self.storeId = groupstage.storeId
} }
static func relationships() -> [Relationship] {
return [
Relationship(type: Tournament.self, keyPath: \BaseGroupStage.tournament),
]
}
} }

@ -89,7 +89,8 @@ class BaseMatch: ModelObject, SyncedStorable, Codable {
super.init() 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.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() 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
@ -109,7 +110,7 @@ class BaseMatch: ModelObject, SyncedStorable, Codable {
func encode(to encoder: Encoder) throws { 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.lastUpdate, forKey: ._lastUpdate) 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)
@ -155,4 +156,11 @@ class BaseMatch: ModelObject, SyncedStorable, Codable {
self.confirmed = match.confirmed self.confirmed = match.confirmed
self.storeId = match.storeId self.storeId = match.storeId
} }
static func relationships() -> [Relationship] {
return [
Relationship(type: Round.self, keyPath: \BaseMatch.round),
Relationship(type: GroupStage.self, keyPath: \BaseMatch.groupStage),
]
}
} }

@ -142,4 +142,10 @@ class BaseMatchScheduler: ModelObject, Storable, Codable {
self.shouldTryToFillUpCourtsAvailable = matchscheduler.shouldTryToFillUpCourtsAvailable self.shouldTryToFillUpCourtsAvailable = matchscheduler.shouldTryToFillUpCourtsAvailable
self.storeId = matchscheduler.storeId self.storeId = matchscheduler.storeId
} }
static func relationships() -> [Relationship] {
return [
Relationship(type: Tournament.self, keyPath: \BaseMatchScheduler.tournament),
]
}
} }

@ -110,4 +110,8 @@ 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] {
return []
}
} }

@ -109,7 +109,8 @@ class BasePlayerRegistration: ModelObject, SyncedStorable, Codable {
super.init() 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.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() 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) ?? ""
@ -134,7 +135,7 @@ class BasePlayerRegistration: ModelObject, SyncedStorable, Codable {
func encode(to encoder: Encoder) throws { 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.lastUpdate, forKey: ._lastUpdate) 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)
@ -185,4 +186,10 @@ class BasePlayerRegistration: ModelObject, SyncedStorable, Codable {
self.hasArrived = playerregistration.hasArrived self.hasArrived = playerregistration.hasArrived
self.storeId = playerregistration.storeId self.storeId = playerregistration.storeId
} }
static func relationships() -> [Relationship] {
return [
Relationship(type: TeamRegistration.self, keyPath: \BasePlayerRegistration.teamRegistration),
]
}
} }

@ -56,7 +56,8 @@ class BasePurchase: ModelObject, SyncedStorable, Codable {
super.init() 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
self.lastUpdate = try container.decodeIfPresent(Date.self, forKey: .lastUpdate) ?? Date() 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) ?? ""
@ -68,7 +69,7 @@ class BasePurchase: ModelObject, SyncedStorable, Codable {
func encode(to encoder: Encoder) throws { 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.lastUpdate, forKey: .lastUpdate) 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)
@ -92,4 +93,10 @@ 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] {
return [
Relationship(type: CustomUser.self, keyPath: \BasePurchase.user),
]
}
} }

@ -65,7 +65,8 @@ class BaseRound: ModelObject, SyncedStorable, Codable {
super.init() 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.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() 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
@ -79,7 +80,7 @@ class BaseRound: ModelObject, SyncedStorable, Codable {
func encode(to encoder: Encoder) throws { 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.lastUpdate, forKey: ._lastUpdate) 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)
@ -107,4 +108,10 @@ class BaseRound: ModelObject, SyncedStorable, Codable {
self.loserBracketMode = round.loserBracketMode self.loserBracketMode = round.loserBracketMode
self.storeId = round.storeId self.storeId = round.storeId
} }
static func relationships() -> [Relationship] {
return [
Relationship(type: Tournament.self, keyPath: \BaseRound.tournament),
]
}
} }

@ -117,7 +117,8 @@ class BaseTeamRegistration: ModelObject, SyncedStorable, Codable {
super.init() 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.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() 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
@ -144,7 +145,7 @@ class BaseTeamRegistration: ModelObject, SyncedStorable, Codable {
func encode(to encoder: Encoder) throws { 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.lastUpdate, forKey: ._lastUpdate) 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)
@ -199,4 +200,10 @@ class BaseTeamRegistration: ModelObject, SyncedStorable, Codable {
self.pointsEarned = teamregistration.pointsEarned self.pointsEarned = teamregistration.pointsEarned
self.storeId = teamregistration.storeId self.storeId = teamregistration.storeId
} }
static func relationships() -> [Relationship] {
return [
Relationship(type: GroupStage.self, keyPath: \BaseTeamRegistration.groupStage),
]
}
} }

@ -57,7 +57,8 @@ class BaseTeamScore: ModelObject, SyncedStorable, Codable {
super.init() 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.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() 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
@ -69,7 +70,7 @@ class BaseTeamScore: ModelObject, SyncedStorable, Codable {
func encode(to encoder: Encoder) throws { 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.lastUpdate, forKey: ._lastUpdate) 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)
@ -98,4 +99,11 @@ class BaseTeamScore: ModelObject, SyncedStorable, Codable {
self.luckyLoser = teamscore.luckyLoser self.luckyLoser = teamscore.luckyLoser
self.storeId = teamscore.storeId self.storeId = teamscore.storeId
} }
static func relationships() -> [Relationship] {
return [
Relationship(type: Match.self, keyPath: \BaseTeamScore.match),
Relationship(type: TeamRegistration.self, keyPath: \BaseTeamScore.teamRegistration),
]
}
} }

@ -254,7 +254,8 @@ class BaseTournament: ModelObject, SyncedStorable, Codable {
super.init() 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.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() 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()
@ -300,7 +301,7 @@ class BaseTournament: ModelObject, SyncedStorable, Codable {
func encode(to encoder: Encoder) throws { 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.lastUpdate, forKey: ._lastUpdate) 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)
@ -393,4 +394,10 @@ 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] {
return [
Relationship(type: Event.self, keyPath: \BaseTournament.event),
]
}
} }

@ -12,7 +12,8 @@
}, },
{ {
"name": "lastUpdate", "name": "lastUpdate",
"type": "Date" "type": "Date",
"option": "fractional"
}, },
{ {
"name": "creator", "name": "creator",

@ -12,7 +12,8 @@
}, },
{ {
"name": "lastUpdate", "name": "lastUpdate",
"type": "Date" "type": "Date",
"option": "fractional"
}, },
{ {
"name": "index", "name": "index",

@ -15,7 +15,8 @@
}, },
{ {
"name": "lastUpdate", "name": "lastUpdate",
"type": "Date" "type": "Date",
"option": "fractional"
}, },
{ {
"name": "username", "name": "username",

@ -12,7 +12,8 @@
}, },
{ {
"name": "lastUpdate", "name": "lastUpdate",
"type": "Date" "type": "Date",
"option": "fractional"
}, },
{ {
"name": "event", "name": "event",

@ -12,7 +12,8 @@
}, },
{ {
"name": "lastUpdate", "name": "lastUpdate",
"type": "Date" "type": "Date",
"option": "fractional"
}, },
{ {
"name": "creator", "name": "creator",

@ -12,7 +12,8 @@
}, },
{ {
"name": "lastUpdate", "name": "lastUpdate",
"type": "Date" "type": "Date",
"option": "fractional"
}, },
{ {
"name": "tournament", "name": "tournament",

@ -14,7 +14,8 @@
}, },
{ {
"name": "lastUpdate", "name": "lastUpdate",
"type": "Date" "type": "Date",
"option": "fractional"
}, },
{ {
"name": "round", "name": "round",

@ -15,7 +15,8 @@
}, },
{ {
"name": "lastUpdate", "name": "lastUpdate",
"type": "Date" "type": "Date",
"option": "fractional"
}, },
{ {
"name": "teamRegistration", "name": "teamRegistration",

@ -11,7 +11,8 @@
}, },
{ {
"name": "lastUpdate", "name": "lastUpdate",
"type": "Date" "type": "Date",
"option": "fractional"
}, },
{ {
"name": "user", "name": "user",

@ -15,7 +15,8 @@
}, },
{ {
"name": "lastUpdate", "name": "lastUpdate",
"type": "Date" "type": "Date",
"option": "fractional"
}, },
{ {
"name": "tournament", "name": "tournament",

@ -15,7 +15,8 @@
}, },
{ {
"name": "lastUpdate", "name": "lastUpdate",
"type": "Date" "type": "Date",
"option": "fractional"
}, },
{ {
"name": "tournament", "name": "tournament",

@ -15,7 +15,8 @@
}, },
{ {
"name": "lastUpdate", "name": "lastUpdate",
"type": "Date" "type": "Date",
"option": "fractional"
}, },
{ {
"name": "match", "name": "match",

@ -15,7 +15,8 @@
}, },
{ {
"name": "lastUpdate", "name": "lastUpdate",
"type": "Date" "type": "Date",
"option": "fractional"
}, },
{ {
"name": "event", "name": "event",

@ -84,6 +84,11 @@ class SwiftModelGenerator:
# Copy method # Copy method
lines.extend(self._generate_copy_method(model_name, properties)) lines.extend(self._generate_copy_method(model_name, properties))
lines.append("")
# Add relationships function
lines.extend(self._generate_relationships(model_name, properties))
lines.append("")
lines.append("}") lines.append("}")
return "\n".join(lines) return "\n".join(lines)
@ -255,6 +260,7 @@ class SwiftModelGenerator:
type_name = prop['type'] type_name = prop['type']
is_optional = prop.get("optional", False) is_optional = prop.get("optional", False)
default_value = prop.get("defaultValue", "nil" if is_optional else self._get_default_value(type_name)) default_value = prop.get("defaultValue", "nil" if is_optional else self._get_default_value(type_name))
option = prop.get("option")
# Use the correct case reference based on observable flag # Use the correct case reference based on observable flag
case_ref = f"_{name}" if is_observable else name case_ref = f"_{name}" if is_observable else name
@ -268,9 +274,20 @@ class SwiftModelGenerator:
lines.append(f" self.{name} = try container.decodeEncrypted(key: .{case_ref})") lines.append(f" self.{name} = try container.decodeEncrypted(key: .{case_ref})")
elif enc_type in ["tournament_payment", "tournament_iscanceled"]: elif enc_type in ["tournament_payment", "tournament_iscanceled"]:
lines.append(f" self.{name} = try Self._decode{name.capitalize()}(container: container)") lines.append(f" self.{name} = try Self._decode{name.capitalize()}(container: container)")
else:
# Handle Date with fractional option
if type_name == "Date" and option == "fractional":
if is_optional:
lines.append(f" if let dateString = try container.decodeIfPresent(String.self, forKey: .{case_ref}) {{")
lines.append(f" self.{name} = Date.iso8601FractionalFormatter.date(from: dateString)")
lines.append(" } else {")
lines.append(f" self.{name} = {default_value}")
lines.append(" }")
else:
lines.append(f" let dateString = try container.decode(String.self, forKey: .{case_ref})")
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(" }") lines.append(" }")
return lines return lines
@ -280,7 +297,9 @@ class SwiftModelGenerator:
for prop in properties: for prop in properties:
name = prop['name'] name = prop['name']
type_name = prop['type']
is_optional = prop.get('optional', False) is_optional = prop.get('optional', False)
option = prop.get("option")
# Use the correct case reference based on observable flag # Use the correct case reference based on observable flag
case_ref = f"_{name}" if is_observable else name case_ref = f"_{name}" if is_observable else name
@ -294,6 +313,16 @@ class SwiftModelGenerator:
lines.append(f" try container.encodeAndEncryptIfPresent(self.{name}.data(using: .utf8), forKey: .{case_ref})") lines.append(f" try container.encodeAndEncryptIfPresent(self.{name}.data(using: .utf8), forKey: .{case_ref})")
elif enc_type in ["tournament_payment", "tournament_iscanceled"]: elif enc_type in ["tournament_payment", "tournament_iscanceled"]:
lines.append(f" try _encode{name.capitalize()}(container: &container)") lines.append(f" try _encode{name.capitalize()}(container: &container)")
else:
if type_name == "Date" and option == "fractional":
if is_optional:
lines.append(f" if let date = self.{name} {{")
lines.append(f" try container.encode(Date.iso8601FractionalFormatter.string(from: date), forKey: .{case_ref})")
lines.append(" } else {")
lines.append(f" try container.encodeNil(forKey: .{case_ref})")
lines.append(" }")
else:
lines.append(f" try container.encode(Date.iso8601FractionalFormatter.string(from: self.{name}), forKey: .{case_ref})")
else: else:
lines.append(f" try container.encode(self.{name}, forKey: .{case_ref})") lines.append(f" try container.encode(self.{name}, forKey: .{case_ref})")
@ -325,6 +354,36 @@ class SwiftModelGenerator:
f" static func filterByStoreIdentifier() -> Bool {{ return {str(filter_by_store).lower()} }}" f" static func filterByStoreIdentifier() -> Bool {{ return {str(filter_by_store).lower()} }}"
] ]
def _generate_relationships(self, model_name, properties: List[Dict[str, Any]]) -> List[str]:
# Find all properties with foreign keys
foreign_key_props = [p for p in properties if "foreignKey" in p]
if not foreign_key_props:
# If no foreign keys, return empty array
return [
" static func relationships() -> [Relationship] {",
" return []",
" }"
]
lines = [
" static func relationships() -> [Relationship] {",
" return ["
]
# Generate relationship entries
for prop in foreign_key_props:
name = prop["name"]
foreign_key = prop["foreignKey"].rstrip('*') # Remove asterisk if present
lines.append(f" Relationship(type: {foreign_key}.self, keyPath: \\Base{model_name}.{name}),")
# Close the array and function
lines.extend([
" ]",
" }"
])
return lines
def _get_default_value(self, type_name: str) -> str: def _get_default_value(self, type_name: str) -> str:
"""Get default value for non-optional types""" """Get default value for non-optional types"""

@ -1,3 +1,15 @@
# Procédure de création de classe
Dans Swift:
- Dans Data > Gen > créer un nouveau fichier json pour la classe
- Le paramètre "foreignKey" permet de générer une méthode qui récupère l'objet parent. Ajouter une étoile permet d'indiquer que l'on cherche l'objet dans le Store de l'objet et non le Store.main.
- Pour générer les fichiers, on se place dans le répertoire de generator.py et on lance la commande : python generator.py -i . -o .
Dans Django:
- Les modèles de base doivent étendre BaseModel.
- Les modèles stockés dans des répertoires doivent étendre SideStoreModel.
- Les classes d'admin doivent étendre AutoUpdateAdmin
# Procédure d'ajout de champ dans une classe # Procédure d'ajout de champ dans une classe
Dans Swift: Dans Swift:

Loading…
Cancel
Save