clean up init

newoffer2025
Raz 6 months ago
parent 12055d9e6f
commit 95c95d1a87
  1. 20
      PadelClubData/Data/Court.swift
  2. 22
      PadelClubData/Data/CustomUser.swift
  3. 29
      PadelClubData/Data/DateInterval.swift
  4. 6
      PadelClubData/Data/Gen/BaseTeamRegistration.swift
  5. 1
      PadelClubData/Data/Gen/TeamRegistration.json
  6. 18
      PadelClubData/Data/Match.swift
  7. 39
      PadelClubData/Data/MatchScheduler.swift
  8. 40
      PadelClubData/Data/PlayerRegistration.swift
  9. 38
      PadelClubData/Data/Round.swift
  10. 72
      PadelClubData/Data/TeamRegistration.swift
  11. 25
      PadelClubData/Data/TeamScore.swift
  12. 6
      PadelClubData/Data/Tournament.swift

@ -16,26 +16,6 @@ final public class Court: BaseCourt {
lhs.id == rhs.id
}
public init(index: Int, club: String, name: String? = nil, exitAllowed: Bool = false, indoor: Bool = false) {
super.init()
self.index = index
self.lastUpdate = Date()
self.club = club
self.name = name
self.exitAllowed = exitAllowed
self.indoor = indoor
}
required init(from decoder: Decoder) throws {
try super.init(from: decoder)
}
required public init() {
super.init()
}
public func courtTitle() -> String {
self.name ?? courtIndexTitle()
}

@ -97,28 +97,6 @@ public class CustomUser: BaseCustomUser, UserBase {
//
// var deviceId: String?
public 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)
// self.lastUpdate = Date()
// self.username = username
// self.firstName = firstName
// self.lastName = lastName
// self.email = email
// self.phone = phone
// self.country = country
// self.loserBracketMode = loserBracketMode
}
required init(from decoder: Decoder) throws {
try super.init(from: decoder)
}
required public init() {
super.init()
}
public func uuid() throws -> UUID {
if let uuid = UUID(uuidString: self.id) {
return uuid

@ -12,35 +12,6 @@ import LeStorage
@Observable
final public class DateInterval: BaseDateInterval {
// static func resourceName() -> String { return "date-intervals" }
// static func tokenExemptedMethods() -> [HTTPMethod] { return [] }
// static func filterByStoreIdentifier() -> Bool { return false }
// static var relationshipNames: [String] = []
//
// var id: String = Store.randomId()
// var lastUpdate: Date
// var event: String
// var courtIndex: Int
// var startDate: Date
// var endDate: Date
public init(event: String, courtIndex: Int, startDate: Date, endDate: Date) {
super.init(event: event, courtIndex: courtIndex, startDate: startDate, endDate: endDate)
// self.lastUpdate = Date()
// self.event = event
// self.courtIndex = courtIndex
// self.startDate = startDate
// self.endDate = endDate
}
required init(from decoder: any Decoder) throws {
try super.init(from: decoder)
}
required public init() {
super.init()
}
var range: Range<Date> {
startDate..<endDate
}

@ -15,7 +15,7 @@ public class BaseTeamRegistration: SyncedModelObject, SyncedStorable {
public var id: String = Store.randomId()
public var tournament: String = ""
public var groupStage: String? = nil
public var registrationDate: Date? = nil
public var registrationDate: Date? = Date()
public var callDate: Date? = nil
public var bracketPosition: Int? = nil
public var groupStagePosition: Int? = nil
@ -39,7 +39,7 @@ public class BaseTeamRegistration: SyncedModelObject, SyncedStorable {
id: String = Store.randomId(),
tournament: String = "",
groupStage: String? = nil,
registrationDate: Date? = nil,
registrationDate: Date? = Date(),
callDate: Date? = nil,
bracketPosition: Int? = nil,
groupStagePosition: Int? = nil,
@ -117,7 +117,7 @@ public class BaseTeamRegistration: SyncedModelObject, SyncedStorable {
self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId()
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
self.registrationDate = try container.decodeIfPresent(Date.self, forKey: ._registrationDate) ?? Date()
self.callDate = try container.decodeIfPresent(Date.self, forKey: ._callDate) ?? nil
self.bracketPosition = try container.decodeIfPresent(Int.self, forKey: ._bracketPosition) ?? nil
self.groupStagePosition = try container.decodeIfPresent(Int.self, forKey: ._groupStagePosition) ?? nil

@ -25,6 +25,7 @@
{
"name": "registrationDate",
"type": "Date",
"defaultValue": "Date()",
"optional": true
},
{

@ -22,20 +22,6 @@ final public class Match: BaseMatch, SideStorable {
public var byeState: Bool = false
public init(round: String? = nil, groupStage: String? = nil, startDate: Date? = nil, endDate: Date? = nil, index: Int, format: MatchFormat? = nil, servingTeamId: String? = nil, winningTeamId: String? = nil, losingTeamId: String? = nil, name: String? = nil, disabled: Bool = false, courtIndex: Int? = nil, confirmed: Bool = false) {
super.init(round: round, groupStage: groupStage, startDate: startDate, endDate: endDate, index: index, format: format, servingTeamId: servingTeamId, winningTeamId: winningTeamId, losingTeamId: losingTeamId, name: name, disabled: disabled, courtIndex: courtIndex, confirmed: confirmed)
}
required init(from decoder: Decoder) throws {
try super.init(from: decoder)
}
required public init() {
super.init()
}
// MARK: - DidSet
public override func didSetStartDate() {
@ -131,7 +117,7 @@ defer {
}
#endif
if roundObject?.groupStageLoserBracket == true {
if roundObject?.isGroupStageLoserBracket() == true {
return "\(index)\(index.ordinalFormattedSuffix()) place"
}
if let groupStageObject {
@ -948,7 +934,7 @@ defer {
public var isLoserBracket: Bool {
if let roundObject {
if roundObject.parent != nil || roundObject.groupStageLoserBracket {
if roundObject.parent != nil || roundObject.isGroupStageLoserBracket() {
return true
}
}

@ -11,44 +11,7 @@ import SwiftUI
@Observable
final public class MatchScheduler: BaseMatchScheduler, SideStorable {
//
// init(tournament: String,
// timeDifferenceLimit: Int = 5,
// loserBracketRotationDifference: Int = 0,
// upperBracketRotationDifference: Int = 1,
// accountUpperBracketBreakTime: Bool = true,
// accountLoserBracketBreakTime: Bool = false,
// randomizeCourts: Bool = true,
// rotationDifferenceIsImportant: Bool = false,
// shouldHandleUpperRoundSlice: Bool = false,
// shouldEndRoundBeforeStartingNext: Bool = true,
//<<<<<<< HEAD
// groupStageChunkCount: Int? = nil, overrideCourtsUnavailability: Bool = false, shouldTryToFillUpCourtsAvailable: Bool = false) {
// super.init()
//=======
// groupStageChunkCount: Int? = nil,
// overrideCourtsUnavailability: Bool = false,
// shouldTryToFillUpCourtsAvailable: Bool = true,
// courtsAvailable: Set<Int> = Set<Int>(),
// simultaneousStart: Bool = true) {
//>>>>>>> main
// self.tournament = tournament
// self.timeDifferenceLimit = timeDifferenceLimit
// self.loserBracketRotationDifference = loserBracketRotationDifference
// self.upperBracketRotationDifference = upperBracketRotationDifference
// self.accountUpperBracketBreakTime = accountUpperBracketBreakTime
// self.accountLoserBracketBreakTime = accountLoserBracketBreakTime
// self.randomizeCourts = randomizeCourts
// self.rotationDifferenceIsImportant = rotationDifferenceIsImportant
// self.shouldHandleUpperRoundSlice = shouldHandleUpperRoundSlice
// self.shouldEndRoundBeforeStartingNext = shouldEndRoundBeforeStartingNext
// self.groupStageChunkCount = groupStageChunkCount
// self.overrideCourtsUnavailability = overrideCourtsUnavailability
// self.shouldTryToFillUpCourtsAvailable = shouldTryToFillUpCourtsAvailable
// self.courtsAvailable = courtsAvailable
// self.simultaneousStart = simultaneousStart
// }
var courtsUnavailability: [DateInterval]? {
guard let event = tournamentObject()?.eventObject() else { return nil }
return event.courtsUnavailability + (overrideCourtsUnavailability ? [] : event.tournamentsCourtsUsed(exluding: tournament))

@ -24,45 +24,7 @@ final public class PlayerRegistration: BasePlayerRegistration, SideStorable {
return "créé par vous-même"
}
}
}
public init(teamRegistration: String? = nil, firstName: String, lastName: String, licenceId: String? = nil, rank: Int? = nil, paymentType: PlayerPaymentType? = nil, sex: PlayerSexType? = nil, tournamentPlayed: Int? = nil, points: Double? = nil, clubName: String? = nil, ligueName: String? = nil, assimilation: String? = nil, phoneNumber: String? = nil, email: String? = nil, birthdate: String? = nil, computedRank: Int = 0, source: PlayerRegistration.PlayerDataSource? = nil, hasArrived: Bool = false, coach: Bool = false, captain: Bool = false, registeredOnline: Bool = false, timeToConfirm: Date? = nil, registrationStatus: PlayerRegistration.RegistrationStatus = PlayerRegistration.RegistrationStatus.waiting, paymentId: String? = nil, clubCode: String? = nil, clubMember: Bool = false) {
super.init()
self.teamRegistration = teamRegistration
self.firstName = firstName
self.lastName = lastName
self.licenceId = licenceId
self.rank = rank
self.paymentType = paymentType
self.sex = sex
self.tournamentPlayed = tournamentPlayed
self.points = points
self.clubName = clubName
self.ligueName = ligueName
self.assimilation = assimilation
self.phoneNumber = phoneNumber
self.email = email
self.birthdate = birthdate
self.computedRank = computedRank
self.source = source
self.hasArrived = hasArrived
self.coach = coach
self.captain = captain
self.registeredOnline = registeredOnline
self.timeToConfirm = timeToConfirm
self.registrationStatus = registrationStatus
self.paymentId = paymentId
self.clubCode = clubCode
self.clubMember = clubMember
}
required init(from decoder: any Decoder) throws {
try super.init(from: decoder)
}
required public init() {
super.init()
}
}
public var tournamentStore: TournamentStore? {
guard let storeId else {

@ -21,28 +21,6 @@ final public class Round: BaseRound, SideStorable {
@ObservationIgnored
private var _cachedLoserRoundsAndChildren: [Round]?
public init(tournament: String, index: Int, parent: String? = nil, matchFormat: MatchFormat? = nil, startDate: Date? = nil, groupStageLoserBracket: Bool = false, loserBracketMode: LoserBracketMode = .automatic) {
super.init(tournament: tournament, index: index, parent: parent, format: matchFormat, startDate: startDate, groupStageLoserBracket: groupStageLoserBracket, loserBracketMode: loserBracketMode)
// self.lastUpdate = Date()
// self.tournament = tournament
// self.index = index
// self.parent = parent
// self.format = matchFormat
// self.startDate = startDate
// self.groupStageLoserBracket = groupStageLoserBracket
// self.loserBracketMode = loserBracketMode
}
required init(from decoder: any Decoder) throws {
try super.init(from: decoder)
}
required public init() {
super.init()
}
// MARK: - DidSet
public override func didSetStartDate() {
@ -265,7 +243,7 @@ defer {
}
#endif
let parentRound = parentRound
if let parentRound, parentRound.parent == nil, groupStageLoserBracket == false, parentRound.loserBracketMode != .automatic {
if let parentRound, parentRound.parent == nil, isGroupStageLoserBracket() == false, parentRound.loserBracketMode != .automatic {
return nil
}
@ -286,7 +264,7 @@ defer {
#endif
let parentRound = parentRound
if let parentRound, parentRound.parent == nil, groupStageLoserBracket == false, parentRound.loserBracketMode != .automatic {
if let parentRound, parentRound.parent == nil, isGroupStageLoserBracket() == false, parentRound.loserBracketMode != .automatic {
return nil
}
@ -647,7 +625,7 @@ defer {
}
public func roundTitle(_ displayStyle: DisplayStyle = .wide, initialMode: Bool = false) -> String {
if groupStageLoserBracket {
if isGroupStageLoserBracket() {
return "Classement Poules"
}
@ -752,11 +730,11 @@ defer {
}
public func isUpperBracket() -> Bool {
return parent == nil && groupStageLoserBracket == false
return parent == nil && isGroupStageLoserBracket() == false
}
public func isLoserBracket() -> Bool {
return parent != nil || groupStageLoserBracket
return parent != nil || isGroupStageLoserBracket()
}
public func deleteLoserBracket() {
@ -793,7 +771,7 @@ defer {
var titles = [String: String]()
let rounds = (0..<roundCount).map { //index 0 is the final
let round = Round(tournament: tournament, index: $0, matchFormat: loserBracketMatchFormat)
let round = Round(tournament: tournament, index: $0, format: loserBracketMatchFormat)
round.parent = id //parent
//titles[round.id] = round.roundTitle(initialMode: true)
return round
@ -911,6 +889,10 @@ defer {
plannedStartDate ?? startDate ?? playedMatches().first?.initialStartDate()
}
public func isGroupStageLoserBracket() -> Bool {
groupStageLoserBracket == true
}
public override func deleteDependencies(store: Store, shouldBeSynchronized: Bool) {
store.deleteDependencies(type: Match.self, shouldBeSynchronized: shouldBeSynchronized) { $0.round == self.id }

@ -14,38 +14,38 @@ final public class TeamRegistration: BaseTeamRegistration, SideStorable {
@ObservationIgnored
var _cachedRestingTime: (Bool, Date?)?
public 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()
// self.storeId = tournament
self.tournament = tournament
self.groupStage = groupStage
self.registrationDate = registrationDate ?? Date()
self.callDate = callDate
self.bracketPosition = bracketPosition
self.groupStagePosition = groupStagePosition
self.comment = comment
self.source = source
self.sourceValue = sourceValue
self.logo = logo
self.name = name
self.walkOut = walkOut
self.wildCardBracket = wildCardBracket
self.wildCardGroupStage = wildCardGroupStage
self.weight = weight
self.lockedWeight = lockedWeight
self.confirmationDate = confirmationDate
self.qualified = qualified
}
// public 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()
//
// // self.storeId = tournament
// self.tournament = tournament
// self.groupStage = groupStage
// self.registrationDate = registrationDate ?? Date()
// self.callDate = callDate
// self.bracketPosition = bracketPosition
// self.groupStagePosition = groupStagePosition
// self.comment = comment
// self.source = source
// self.sourceValue = sourceValue
// self.logo = logo
// self.name = name
// self.walkOut = walkOut
// self.wildCardBracket = wildCardBracket
// self.wildCardGroupStage = wildCardGroupStage
// self.weight = weight
// self.lockedWeight = lockedWeight
// self.confirmationDate = confirmationDate
// self.qualified = qualified
// }
//
public func hasRegisteredOnline() -> Bool {
players().anySatisfy({ $0.registeredOnline })
}
@ -72,14 +72,6 @@ final public class TeamRegistration: BaseTeamRegistration, SideStorable {
walkOut
}
required init(from decoder: any Decoder) throws {
try super.init(from: decoder)
}
required public init() {
super.init()
}
public var tournamentStore: TournamentStore? {
return TournamentLibrary.shared.store(tournamentId: self.tournament)
}

@ -27,33 +27,14 @@ final public class TeamScore: BaseTeamScore, SideStorable {
// var luckyLoser: Int?
//
// var storeId: String? = nil
init(match: String, teamRegistration: String? = nil, score: String? = nil, walkOut: Int? = nil, luckyLoser: Int? = nil) {
super.init(match: match, teamRegistration: teamRegistration, score: score, walkOut: walkOut, luckyLoser: luckyLoser)
// self.match = match
// self.teamRegistration = teamRegistration
//// self.playerRegistrations = playerRegistrations
// self.score = score
// self.walkOut = walkOut
// self.luckyLoser = luckyLoser
}
init(match: String, team: TeamRegistration?) {
super.init(match: match)
convenience init(match: String, team: TeamRegistration?) {
self.init(match: match)
if let team {
self.teamRegistration = team.id
}
}
required init(from decoder: Decoder) throws {
try super.init(from: decoder)
}
required public init() {
super.init()
}
var tournamentStore: TournamentStore? {
guard let storeId else {
fatalError("missing store id for \(String(describing: type(of: self)))")

@ -1415,7 +1415,7 @@ defer {
let matchCount = RoundRule.numberOfMatches(forTeams: minimalBracketTeamCount ?? bracketTeamCount())
let rounds = (0..<roundCount).map { //index 0 is the final
return Round(tournament: id, index: $0, matchFormat: matchFormat, loserBracketMode: loserBracketMode)
return Round(tournament: id, index: $0, format: matchFormat, loserBracketMode: loserBracketMode)
}
if rounds.isEmpty {
@ -1881,7 +1881,7 @@ defer {
}
public func groupStageLoserBracket() -> Round? {
self.tournamentStore?.rounds.first(where: { $0.groupStageLoserBracket })
self.tournamentStore?.rounds.first(where: { $0.isGroupStageLoserBracket() })
}
public func groupStageLoserBracketsInitialPlace() -> Int {
@ -2026,7 +2026,7 @@ defer {
public func addNewRound(_ roundIndex: Int) async {
await MainActor.run {
let round = Round(tournament: id, index: roundIndex, matchFormat: matchFormat)
let round = Round(tournament: id, index: roundIndex, format: matchFormat)
let matchCount = RoundRule.numberOfMatches(forRoundIndex: roundIndex)
let matchStartIndex = RoundRule.matchIndex(fromRoundIndex: roundIndex)
let nextRound = round.nextRound()

Loading…
Cancel
Save