diff --git a/PadelClub/Data/Gen/BaseClub.swift b/PadelClub/Data/Gen/BaseClub.swift index 8439123..df90ab9 100644 --- a/PadelClub/Data/Gen/BaseClub.swift +++ b/PadelClub/Data/Gen/BaseClub.swift @@ -81,7 +81,8 @@ class BaseClub: ModelObject, SyncedStorable, Codable { super.init() let container = try decoder.container(keyedBy: CodingKeys.self) 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.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? "" self.acronym = try container.decodeIfPresent(String.self, forKey: ._acronym) ?? "" @@ -99,7 +100,7 @@ class BaseClub: ModelObject, SyncedStorable, Codable { func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) 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.name, forKey: ._name) try container.encode(self.acronym, forKey: ._acronym) @@ -136,4 +137,10 @@ 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), + ] + } + } \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseCourt.swift b/PadelClub/Data/Gen/BaseCourt.swift index f3b4f5c..d9d55e5 100644 --- a/PadelClub/Data/Gen/BaseCourt.swift +++ b/PadelClub/Data/Gen/BaseCourt.swift @@ -53,7 +53,8 @@ class BaseCourt: ModelObject, SyncedStorable, Codable { super.init() let container = try decoder.container(keyedBy: CodingKeys.self) 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.club = try container.decodeIfPresent(String.self, forKey: ._club) ?? "" 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 { var container = encoder.container(keyedBy: CodingKeys.self) 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.club, forKey: ._club) try container.encode(self.name, forKey: ._name) @@ -86,4 +87,10 @@ class BaseCourt: ModelObject, SyncedStorable, Codable { self.exitAllowed = court.exitAllowed self.indoor = court.indoor } + static func relationships() -> [Relationship] { + return [ + Relationship(type: Club.self, keyPath: \BaseCourt.club), + ] + } + } \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseCustomUser.swift b/PadelClub/Data/Gen/BaseCustomUser.swift index 7c5463a..65eda94 100644 --- a/PadelClub/Data/Gen/BaseCustomUser.swift +++ b/PadelClub/Data/Gen/BaseCustomUser.swift @@ -117,7 +117,8 @@ class BaseCustomUser: ModelObject, SyncedStorable, Codable { super.init() let container = try decoder.container(keyedBy: CodingKeys.self) 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.email = try container.decodeIfPresent(String.self, forKey: ._email) ?? "" self.clubs = try container.decodeIfPresent([String].self, forKey: ._clubs) ?? [] @@ -144,7 +145,7 @@ class BaseCustomUser: ModelObject, SyncedStorable, Codable { func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) 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.email, forKey: ._email) try container.encode(self.clubs, forKey: ._clubs) @@ -194,4 +195,8 @@ class BaseCustomUser: ModelObject, SyncedStorable, Codable { self.loserBracketMode = customuser.loserBracketMode self.deviceId = customuser.deviceId } + static func relationships() -> [Relationship] { + return [] + } + } \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseDateInterval.swift b/PadelClub/Data/Gen/BaseDateInterval.swift index 1c678f0..626c433 100644 --- a/PadelClub/Data/Gen/BaseDateInterval.swift +++ b/PadelClub/Data/Gen/BaseDateInterval.swift @@ -49,7 +49,8 @@ class BaseDateInterval: ModelObject, SyncedStorable, Codable { super.init() let container = try decoder.container(keyedBy: CodingKeys.self) 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.courtIndex = try container.decodeIfPresent(Int.self, forKey: ._courtIndex) ?? 0 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 { var container = encoder.container(keyedBy: CodingKeys.self) 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.courtIndex, forKey: ._courtIndex) try container.encode(self.startDate, forKey: ._startDate) @@ -75,4 +76,8 @@ class BaseDateInterval: ModelObject, SyncedStorable, Codable { self.startDate = dateinterval.startDate self.endDate = dateinterval.endDate } + static func relationships() -> [Relationship] { + return [] + } + } \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseEvent.swift b/PadelClub/Data/Gen/BaseEvent.swift index b184516..d47bc8b 100644 --- a/PadelClub/Data/Gen/BaseEvent.swift +++ b/PadelClub/Data/Gen/BaseEvent.swift @@ -53,7 +53,8 @@ class BaseEvent: ModelObject, SyncedStorable, Codable { super.init() let container = try decoder.container(keyedBy: CodingKeys.self) 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.club = try container.decodeIfPresent(String.self, forKey: ._club) ?? nil 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 { var container = encoder.container(keyedBy: CodingKeys.self) 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.club, forKey: ._club) try container.encode(self.creationDate, forKey: ._creationDate) @@ -92,4 +93,11 @@ class BaseEvent: ModelObject, SyncedStorable, Codable { self.name = event.name self.tenupId = event.tenupId } + static func relationships() -> [Relationship] { + return [ + Relationship(type: CustomUser.self, keyPath: \BaseEvent.creator), + Relationship(type: Club.self, keyPath: \BaseEvent.club), + ] + } + } \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseGroupStage.swift b/PadelClub/Data/Gen/BaseGroupStage.swift index dd92f1d..11f3669 100644 --- a/PadelClub/Data/Gen/BaseGroupStage.swift +++ b/PadelClub/Data/Gen/BaseGroupStage.swift @@ -65,7 +65,8 @@ class BaseGroupStage: ModelObject, SyncedStorable, Codable { super.init() let container = try decoder.container(keyedBy: CodingKeys.self) 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.index = try container.decodeIfPresent(Int.self, forKey: ._index) ?? 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 { var container = encoder.container(keyedBy: CodingKeys.self) 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.index, forKey: ._index) try container.encode(self.size, forKey: ._size) @@ -107,4 +108,10 @@ class BaseGroupStage: ModelObject, SyncedStorable, Codable { self.step = groupstage.step self.storeId = groupstage.storeId } -} \ No newline at end of file + static func relationships() -> [Relationship] { + return [ + Relationship(type: Tournament.self, keyPath: \BaseGroupStage.tournament), + ] + } + +} diff --git a/PadelClub/Data/Gen/BaseMatch.swift b/PadelClub/Data/Gen/BaseMatch.swift index eeadae7..2f87ecc 100644 --- a/PadelClub/Data/Gen/BaseMatch.swift +++ b/PadelClub/Data/Gen/BaseMatch.swift @@ -89,7 +89,8 @@ class BaseMatch: ModelObject, SyncedStorable, Codable { super.init() let container = try decoder.container(keyedBy: CodingKeys.self) 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.groupStage = try container.decodeIfPresent(String.self, forKey: ._groupStage) ?? 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 { var container = encoder.container(keyedBy: CodingKeys.self) 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.groupStage, forKey: ._groupStage) try container.encode(self.startDate, forKey: ._startDate) @@ -155,4 +156,11 @@ class BaseMatch: ModelObject, SyncedStorable, Codable { self.confirmed = match.confirmed self.storeId = match.storeId } + static func relationships() -> [Relationship] { + return [ + Relationship(type: Round.self, keyPath: \BaseMatch.round), + Relationship(type: GroupStage.self, keyPath: \BaseMatch.groupStage), + ] + } + } \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseMatchScheduler.swift b/PadelClub/Data/Gen/BaseMatchScheduler.swift index 2fbcda4..bd7163a 100644 --- a/PadelClub/Data/Gen/BaseMatchScheduler.swift +++ b/PadelClub/Data/Gen/BaseMatchScheduler.swift @@ -142,4 +142,10 @@ class BaseMatchScheduler: ModelObject, Storable, Codable { self.shouldTryToFillUpCourtsAvailable = matchscheduler.shouldTryToFillUpCourtsAvailable self.storeId = matchscheduler.storeId } -} + static func relationships() -> [Relationship] { + return [ + Relationship(type: Tournament.self, keyPath: \BaseMatchScheduler.tournament), + ] + } + +} \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseMonthData.swift b/PadelClub/Data/Gen/BaseMonthData.swift index 5ee2df1..5bb1d57 100644 --- a/PadelClub/Data/Gen/BaseMonthData.swift +++ b/PadelClub/Data/Gen/BaseMonthData.swift @@ -110,4 +110,8 @@ class BaseMonthData: ModelObject, Storable, Codable { self.dataModelIdentifier = monthdata.dataModelIdentifier self.fileModelIdentifier = monthdata.fileModelIdentifier } -} + static func relationships() -> [Relationship] { + return [] + } + +} \ No newline at end of file diff --git a/PadelClub/Data/Gen/BasePlayerRegistration.swift b/PadelClub/Data/Gen/BasePlayerRegistration.swift index 4b146da..f82711b 100644 --- a/PadelClub/Data/Gen/BasePlayerRegistration.swift +++ b/PadelClub/Data/Gen/BasePlayerRegistration.swift @@ -109,7 +109,8 @@ class BasePlayerRegistration: ModelObject, SyncedStorable, Codable { super.init() let container = try decoder.container(keyedBy: CodingKeys.self) 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.firstName = try container.decodeIfPresent(String.self, forKey: ._firstName) ?? "" self.lastName = try container.decodeIfPresent(String.self, forKey: ._lastName) ?? "" @@ -134,7 +135,7 @@ class BasePlayerRegistration: ModelObject, SyncedStorable, Codable { func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) 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.firstName, forKey: ._firstName) try container.encode(self.lastName, forKey: ._lastName) @@ -185,4 +186,10 @@ class BasePlayerRegistration: ModelObject, SyncedStorable, Codable { self.hasArrived = playerregistration.hasArrived self.storeId = playerregistration.storeId } + static func relationships() -> [Relationship] { + return [ + Relationship(type: TeamRegistration.self, keyPath: \BasePlayerRegistration.teamRegistration), + ] + } + } \ No newline at end of file diff --git a/PadelClub/Data/Gen/BasePurchase.swift b/PadelClub/Data/Gen/BasePurchase.swift index 4b544dc..e5ad6d6 100644 --- a/PadelClub/Data/Gen/BasePurchase.swift +++ b/PadelClub/Data/Gen/BasePurchase.swift @@ -56,7 +56,8 @@ class BasePurchase: ModelObject, SyncedStorable, Codable { super.init() let container = try decoder.container(keyedBy: CodingKeys.self) 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.purchaseDate = try container.decodeIfPresent(Date.self, forKey: .purchaseDate) ?? Date() self.productId = try container.decodeIfPresent(String.self, forKey: .productId) ?? "" @@ -68,7 +69,7 @@ class BasePurchase: ModelObject, SyncedStorable, Codable { func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) 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.encode(self.purchaseDate, forKey: .purchaseDate) try container.encode(self.productId, forKey: .productId) @@ -92,4 +93,10 @@ 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), + ] + } + } \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseRound.swift b/PadelClub/Data/Gen/BaseRound.swift index d0b5402..4115b21 100644 --- a/PadelClub/Data/Gen/BaseRound.swift +++ b/PadelClub/Data/Gen/BaseRound.swift @@ -65,7 +65,8 @@ class BaseRound: ModelObject, SyncedStorable, Codable { super.init() let container = try decoder.container(keyedBy: CodingKeys.self) 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.index = try container.decodeIfPresent(Int.self, forKey: ._index) ?? 0 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 { var container = encoder.container(keyedBy: CodingKeys.self) 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.index, forKey: ._index) try container.encode(self.parent, forKey: ._parent) @@ -107,4 +108,10 @@ class BaseRound: ModelObject, SyncedStorable, Codable { self.loserBracketMode = round.loserBracketMode self.storeId = round.storeId } + static func relationships() -> [Relationship] { + return [ + Relationship(type: Tournament.self, keyPath: \BaseRound.tournament), + ] + } + } \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseTeamRegistration.swift b/PadelClub/Data/Gen/BaseTeamRegistration.swift index 007ef8d..bc22dcf 100644 --- a/PadelClub/Data/Gen/BaseTeamRegistration.swift +++ b/PadelClub/Data/Gen/BaseTeamRegistration.swift @@ -117,7 +117,8 @@ class BaseTeamRegistration: ModelObject, SyncedStorable, Codable { super.init() let container = try decoder.container(keyedBy: CodingKeys.self) 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.groupStage = try container.decodeIfPresent(String.self, forKey: ._groupStage) ?? 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 { var container = encoder.container(keyedBy: CodingKeys.self) 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.groupStage, forKey: ._groupStage) try container.encode(self.registrationDate, forKey: ._registrationDate) @@ -199,4 +200,10 @@ class BaseTeamRegistration: ModelObject, SyncedStorable, Codable { self.pointsEarned = teamregistration.pointsEarned self.storeId = teamregistration.storeId } + static func relationships() -> [Relationship] { + return [ + Relationship(type: GroupStage.self, keyPath: \BaseTeamRegistration.groupStage), + ] + } + } \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseTeamScore.swift b/PadelClub/Data/Gen/BaseTeamScore.swift index b4c415f..b9d6508 100644 --- a/PadelClub/Data/Gen/BaseTeamScore.swift +++ b/PadelClub/Data/Gen/BaseTeamScore.swift @@ -57,7 +57,8 @@ class BaseTeamScore: ModelObject, SyncedStorable, Codable { super.init() let container = try decoder.container(keyedBy: CodingKeys.self) 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.teamRegistration = try container.decodeIfPresent(String.self, forKey: ._teamRegistration) ?? 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 { var container = encoder.container(keyedBy: CodingKeys.self) 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.teamRegistration, forKey: ._teamRegistration) try container.encode(self.score, forKey: ._score) @@ -98,4 +99,11 @@ class BaseTeamScore: ModelObject, SyncedStorable, Codable { self.luckyLoser = teamscore.luckyLoser self.storeId = teamscore.storeId } + static func relationships() -> [Relationship] { + return [ + Relationship(type: Match.self, keyPath: \BaseTeamScore.match), + Relationship(type: TeamRegistration.self, keyPath: \BaseTeamScore.teamRegistration), + ] + } + } \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseTournament.swift b/PadelClub/Data/Gen/BaseTournament.swift index ed5b100..d5c8a60 100644 --- a/PadelClub/Data/Gen/BaseTournament.swift +++ b/PadelClub/Data/Gen/BaseTournament.swift @@ -254,7 +254,8 @@ class BaseTournament: ModelObject, SyncedStorable, Codable { super.init() let container = try decoder.container(keyedBy: CodingKeys.self) 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.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? nil 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 { var container = encoder.container(keyedBy: CodingKeys.self) 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.name, forKey: ._name) try container.encode(self.startDate, forKey: ._startDate) @@ -393,4 +394,10 @@ 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), + ] + } + } \ No newline at end of file diff --git a/PadelClub/Data/Gen/Club.json b/PadelClub/Data/Gen/Club.json index 683e716..08f7b14 100644 --- a/PadelClub/Data/Gen/Club.json +++ b/PadelClub/Data/Gen/Club.json @@ -12,7 +12,8 @@ }, { "name": "lastUpdate", - "type": "Date" + "type": "Date", + "option": "fractional" }, { "name": "creator", diff --git a/PadelClub/Data/Gen/Court.json b/PadelClub/Data/Gen/Court.json index f2037bb..46a6c61 100644 --- a/PadelClub/Data/Gen/Court.json +++ b/PadelClub/Data/Gen/Court.json @@ -12,7 +12,8 @@ }, { "name": "lastUpdate", - "type": "Date" + "type": "Date", + "option": "fractional" }, { "name": "index", diff --git a/PadelClub/Data/Gen/CustomUser.json b/PadelClub/Data/Gen/CustomUser.json index b7e3595..c45cf14 100644 --- a/PadelClub/Data/Gen/CustomUser.json +++ b/PadelClub/Data/Gen/CustomUser.json @@ -15,7 +15,8 @@ }, { "name": "lastUpdate", - "type": "Date" + "type": "Date", + "option": "fractional" }, { "name": "username", diff --git a/PadelClub/Data/Gen/DateInterval.json b/PadelClub/Data/Gen/DateInterval.json index e046b16..7e711c3 100644 --- a/PadelClub/Data/Gen/DateInterval.json +++ b/PadelClub/Data/Gen/DateInterval.json @@ -12,7 +12,8 @@ }, { "name": "lastUpdate", - "type": "Date" + "type": "Date", + "option": "fractional" }, { "name": "event", diff --git a/PadelClub/Data/Gen/Event.json b/PadelClub/Data/Gen/Event.json index b8f1bec..38000dd 100644 --- a/PadelClub/Data/Gen/Event.json +++ b/PadelClub/Data/Gen/Event.json @@ -12,7 +12,8 @@ }, { "name": "lastUpdate", - "type": "Date" + "type": "Date", + "option": "fractional" }, { "name": "creator", diff --git a/PadelClub/Data/Gen/GroupStage.json b/PadelClub/Data/Gen/GroupStage.json index eb0627e..4bb5e96 100644 --- a/PadelClub/Data/Gen/GroupStage.json +++ b/PadelClub/Data/Gen/GroupStage.json @@ -12,7 +12,8 @@ }, { "name": "lastUpdate", - "type": "Date" + "type": "Date", + "option": "fractional" }, { "name": "tournament", diff --git a/PadelClub/Data/Gen/Match.json b/PadelClub/Data/Gen/Match.json index ef04e08..153bea5 100644 --- a/PadelClub/Data/Gen/Match.json +++ b/PadelClub/Data/Gen/Match.json @@ -14,7 +14,8 @@ }, { "name": "lastUpdate", - "type": "Date" + "type": "Date", + "option": "fractional" }, { "name": "round", diff --git a/PadelClub/Data/Gen/PlayerRegistration.json b/PadelClub/Data/Gen/PlayerRegistration.json index c457557..f350772 100644 --- a/PadelClub/Data/Gen/PlayerRegistration.json +++ b/PadelClub/Data/Gen/PlayerRegistration.json @@ -15,7 +15,8 @@ }, { "name": "lastUpdate", - "type": "Date" + "type": "Date", + "option": "fractional" }, { "name": "teamRegistration", diff --git a/PadelClub/Data/Gen/Purchase.json b/PadelClub/Data/Gen/Purchase.json index 660d9a2..bb8bdeb 100644 --- a/PadelClub/Data/Gen/Purchase.json +++ b/PadelClub/Data/Gen/Purchase.json @@ -11,7 +11,8 @@ }, { "name": "lastUpdate", - "type": "Date" + "type": "Date", + "option": "fractional" }, { "name": "user", diff --git a/PadelClub/Data/Gen/Round.json b/PadelClub/Data/Gen/Round.json index 6004232..9120c80 100644 --- a/PadelClub/Data/Gen/Round.json +++ b/PadelClub/Data/Gen/Round.json @@ -15,7 +15,8 @@ }, { "name": "lastUpdate", - "type": "Date" + "type": "Date", + "option": "fractional" }, { "name": "tournament", diff --git a/PadelClub/Data/Gen/TeamRegistration.json b/PadelClub/Data/Gen/TeamRegistration.json index 88ac151..2a25c51 100644 --- a/PadelClub/Data/Gen/TeamRegistration.json +++ b/PadelClub/Data/Gen/TeamRegistration.json @@ -15,7 +15,8 @@ }, { "name": "lastUpdate", - "type": "Date" + "type": "Date", + "option": "fractional" }, { "name": "tournament", diff --git a/PadelClub/Data/Gen/TeamScore.json b/PadelClub/Data/Gen/TeamScore.json index 7475164..b283e88 100644 --- a/PadelClub/Data/Gen/TeamScore.json +++ b/PadelClub/Data/Gen/TeamScore.json @@ -15,7 +15,8 @@ }, { "name": "lastUpdate", - "type": "Date" + "type": "Date", + "option": "fractional" }, { "name": "match", diff --git a/PadelClub/Data/Gen/Tournament.json b/PadelClub/Data/Gen/Tournament.json index e5368f9..3f24abf 100644 --- a/PadelClub/Data/Gen/Tournament.json +++ b/PadelClub/Data/Gen/Tournament.json @@ -15,7 +15,8 @@ }, { "name": "lastUpdate", - "type": "Date" + "type": "Date", + "option": "fractional" }, { "name": "event", diff --git a/PadelClub/Data/Gen/generator.py b/PadelClub/Data/Gen/generator.py index 68cb248..b2369c9 100644 --- a/PadelClub/Data/Gen/generator.py +++ b/PadelClub/Data/Gen/generator.py @@ -84,6 +84,11 @@ class SwiftModelGenerator: # Copy method 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("}") return "\n".join(lines) @@ -255,6 +260,7 @@ class SwiftModelGenerator: type_name = prop['type'] is_optional = prop.get("optional", False) 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 case_ref = f"_{name}" if is_observable else name @@ -269,8 +275,19 @@ class SwiftModelGenerator: elif enc_type in ["tournament_payment", "tournament_iscanceled"]: lines.append(f" self.{name} = try Self._decode{name.capitalize()}(container: container)") else: - lines.append(f" self.{name} = try container.decodeIfPresent({type_name}.self, forKey: .{case_ref}) ?? {default_value}") - + # 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: + lines.append(f" self.{name} = try container.decodeIfPresent({type_name}.self, forKey: .{case_ref}) ?? {default_value}") lines.append(" }") return lines @@ -280,7 +297,9 @@ class SwiftModelGenerator: for prop in properties: name = prop['name'] + type_name = prop['type'] is_optional = prop.get('optional', False) + option = prop.get("option") # Use the correct case reference based on observable flag case_ref = f"_{name}" if is_observable else name @@ -295,7 +314,17 @@ class SwiftModelGenerator: elif enc_type in ["tournament_payment", "tournament_iscanceled"]: lines.append(f" try _encode{name.capitalize()}(container: &container)") else: - lines.append(f" try container.encode(self.{name}, forKey: .{case_ref})") + 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: + lines.append(f" try container.encode(self.{name}, forKey: .{case_ref})") lines.append(" }") return lines @@ -325,6 +354,36 @@ class SwiftModelGenerator: 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: """Get default value for non-optional types""" diff --git a/PadelClub/Data/README.md b/PadelClub/Data/README.md index e63debb..22a1795 100644 --- a/PadelClub/Data/README.md +++ b/PadelClub/Data/README.md @@ -1,4 +1,16 @@ -# Procédure d'ajout de champ dans une classe +# 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 Dans Swift: - Ajouter le champ dans classe