diff --git a/PadelClub/Data/MockData.swift b/PadelClub/Data/MockData.swift index d2bd29a..30adfa2 100644 --- a/PadelClub/Data/MockData.swift +++ b/PadelClub/Data/MockData.swift @@ -61,6 +61,6 @@ extension TeamRegistration { extension PlayerRegistration { static func mock() -> PlayerRegistration { - PlayerRegistration(firstName: "Raz", lastName: "Shark", sex: 1) + PlayerRegistration(firstName: "Raz", lastName: "Shark", sex: .male) } } diff --git a/PadelClub/Data/PlayerRegistration.swift b/PadelClub/Data/PlayerRegistration.swift index 428bd6c..74d7196 100644 --- a/PadelClub/Data/PlayerRegistration.swift +++ b/PadelClub/Data/PlayerRegistration.swift @@ -19,7 +19,7 @@ class PlayerRegistration: ModelObject, Storable { var licenceId: String? var rank: Int? var paymentType: PlayerPaymentType? - var sex: Int //todo + var sex: PlayerSexType? var tournamentPlayed: Int? var points: Double? @@ -36,7 +36,7 @@ class PlayerRegistration: ModelObject, Storable { var hasArrived: Bool = false - internal init(teamRegistration: String? = nil, firstName: String, lastName: String, licenceId: String? = nil, rank: Int? = nil, paymentType: PlayerPaymentType? = nil, sex: Int, source: PlayerDataSource? = nil) { + internal init(teamRegistration: String? = nil, firstName: String, lastName: String, licenceId: String? = nil, rank: Int? = nil, paymentType: PlayerPaymentType? = nil, sex: PlayerSexType?, source: PlayerDataSource? = nil) { self.teamRegistration = teamRegistration self.firstName = firstName self.lastName = lastName @@ -53,7 +53,7 @@ class PlayerRegistration: ModelObject, Storable { self.lastName = importedPlayer.lastName ?? "" self.licenceId = importedPlayer.license ?? nil self.rank = Int(importedPlayer.rank) - self.sex = importedPlayer.male ? 1 : 0 + self.sex = importedPlayer.male ? .male : .female self.tournamentPlayed = importedPlayer.tournamentPlayed self.points = importedPlayer.getPoints() self.clubName = importedPlayer.clubName @@ -74,14 +74,14 @@ class PlayerRegistration: ModelObject, Storable { source = .beachPadel if sexUnknown { if sex == 1 && FileImportManager.shared.foundInWomenData(license: federalData[3]) { - self.sex = 0 + self.sex = .female } else if FileImportManager.shared.foundInMenData(license: federalData[3]) { - self.sex = 1 + self.sex = .male } else { - self.sex = -1 + self.sex = nil } } else { - self.sex = sex + self.sex = PlayerSexType(rawValue: sex) } } @@ -243,7 +243,7 @@ class PlayerRegistration: ModelObject, Storable { } func isMalePlayer() -> Bool { - sex == 1 + sex == .male } func validateLicenceId(_ year: Int) { @@ -284,7 +284,7 @@ class PlayerRegistration: ModelObject, Storable { case beachPadel = 1 } - enum PlayerSexType: Int, CaseIterable, Identifiable, Codable { + enum PlayerSexType: Int, Hashable, CaseIterable, Identifiable, Codable { init?(rawValue: Int?) { guard let value = rawValue else { return nil } self.init(rawValue: value) diff --git a/PadelClub/Data/TeamRegistration.swift b/PadelClub/Data/TeamRegistration.swift index 8d2f3a2..0c6bdb7 100644 --- a/PadelClub/Data/TeamRegistration.swift +++ b/PadelClub/Data/TeamRegistration.swift @@ -244,7 +244,7 @@ class TeamRegistration: ModelObject, Storable { func players() -> [PlayerRegistration] { Store.main.filter { $0.teamRegistration == self.id }.sorted { (lhs, rhs) in let predicates: [AreInIncreasingOrder] = [ - { $0.sex < $1.sex }, + { $0.sex?.rawValue ?? 0 < $1.sex?.rawValue ?? 0 }, { $0.rank ?? 0 < $1.rank ?? 0 }, { $0.lastName < $1.lastName}, { $0.firstName < $1.firstName } @@ -278,7 +278,7 @@ class TeamRegistration: ModelObject, Storable { func missingPlayerType(inTournamentCategory tournamentCategory: TournamentCategory) -> [Int] { let players = unsortedPlayers() if players.count >= 2 { return [] } - let s = players.map { $0.sex } + let s = players.compactMap { $0.sex?.rawValue } var missing = tournamentCategory.mandatoryPlayerType() s.forEach { i in if let index = missing.firstIndex(of: i) { diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index 918a6c1..ef879c5 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -32,7 +32,6 @@ class Tournament : ModelObject, Storable { var federalLevelCategory: TournamentLevel var federalAgeCategory: FederalTournamentAge var groupStageCourtCount: Int? - var seedCount: Int var closedRegistrationDate: Date? var groupStageAdditionalQualified: Int var courtCount: Int = 2 @@ -48,7 +47,7 @@ class Tournament : ModelObject, Storable { @ObservationIgnored var navigationPath: [Screen] = [] - internal init(event: String? = nil, name: String? = nil, startDate: Date = Date(), endDate: Date? = nil, creationDate: Date = Date(), isPrivate: Bool = true, groupStageFormat: MatchFormat? = nil, roundFormat: MatchFormat? = nil, loserRoundFormat: MatchFormat? = nil, groupStageSortMode: GroupStageOrderingMode, groupStageCount: Int = 4, rankSourceDate: Date? = nil, dayDuration: Int = 1, teamCount: Int = 24, teamSorting: TeamSortingType? = nil, federalCategory: TournamentCategory, federalLevelCategory: TournamentLevel, federalAgeCategory: FederalTournamentAge, groupStageCourtCount: Int? = nil, seedCount: Int = 8, closedRegistrationDate: Date? = nil, groupStageAdditionalQualified: Int = 0, courtCount: Int = 2, prioritizeClubMembers: Bool = false, qualifiedPerGroupStage: Int = 1, teamsPerGroupStage: Int = 4, entryFee: Double? = nil) { + internal init(event: String? = nil, name: String? = nil, startDate: Date = Date(), endDate: Date? = nil, creationDate: Date = Date(), isPrivate: Bool = true, groupStageFormat: MatchFormat? = nil, roundFormat: MatchFormat? = nil, loserRoundFormat: MatchFormat? = nil, groupStageSortMode: GroupStageOrderingMode, groupStageCount: Int = 4, rankSourceDate: Date? = nil, dayDuration: Int = 1, teamCount: Int = 24, teamSorting: TeamSortingType? = nil, federalCategory: TournamentCategory, federalLevelCategory: TournamentLevel, federalAgeCategory: FederalTournamentAge, groupStageCourtCount: Int? = nil, closedRegistrationDate: Date? = nil, groupStageAdditionalQualified: Int = 0, courtCount: Int = 2, prioritizeClubMembers: Bool = false, qualifiedPerGroupStage: Int = 1, teamsPerGroupStage: Int = 4, entryFee: Double? = nil) { self.event = event self.name = name self.startDate = startDate @@ -68,7 +67,6 @@ class Tournament : ModelObject, Storable { self.federalLevelCategory = federalLevelCategory self.federalAgeCategory = federalAgeCategory self.groupStageCourtCount = groupStageCourtCount - self.seedCount = seedCount self.closedRegistrationDate = closedRegistrationDate self.groupStageAdditionalQualified = groupStageAdditionalQualified self.courtCount = courtCount @@ -563,7 +561,7 @@ class Tournament : ModelObject, Storable { let selectedTeams : [TeamRegistration] = selectedSortedTeams() let callDateIssue : [TeamRegistration] = selectedTeams.filter { $0.callDate != nil && isStartDateIsDifferentThanCallDate($0) } let duplicates : [PlayerRegistration] = duplicates(in: players) - let problematicPlayers : [PlayerRegistration] = players.filter({ $0.sex == -1 }) + let problematicPlayers : [PlayerRegistration] = players.filter({ $0.sex == nil }) let inadequatePlayers : [PlayerRegistration] = inadequatePlayers(in: players) let playersWithoutValidLicense : [PlayerRegistration] = playersWithoutValidLicense(in: players) let playersMissing : [TeamRegistration] = selectedTeams.filter({ $0.unsortedPlayers().count < 2 }) @@ -697,7 +695,7 @@ class Tournament : ModelObject, Storable { let dataURLs = SourceFileManager.shared.allFiles.filter({ $0.dateFromPath == newDate }) let sources = dataURLs.map { CSVParser(url: $0) } - try await player.updateRank(from: sources, lastRank: (player.sex == 0 ? lastRankWoman : lastRankMan) ?? 0) + try await player.updateRank(from: sources, lastRank: (player.sex == .female ? lastRankWoman : lastRankMan) ?? 0) } } @@ -1286,7 +1284,6 @@ extension Tournament { case _federalLevelCategory = "federalLevelCategory" case _federalAgeCategory = "federalAgeCategory" case _groupStageCourtCount = "groupStageCourtCount" - case _seedCount = "seedCount" case _closedRegistrationDate = "closedRegistrationDate" case _groupStageAdditionalQualified = "groupStageAdditionalQualified" case _courtCount = "courtCount" @@ -1365,7 +1362,7 @@ extension Tournament { } static func fake() -> Tournament { - return Tournament(event: "Roland Garros", name: "Magic P100", startDate: Date(), endDate: Date(), creationDate: Date(), isPrivate: false, groupStageFormat: .nineGames, roundFormat: nil, loserRoundFormat: nil, groupStageSortMode: .snake, groupStageCount: 4, rankSourceDate: nil, dayDuration: 2, teamCount: 24, teamSorting: .rank, federalCategory: .men, federalLevelCategory: .p100, federalAgeCategory: .a45, groupStageCourtCount: nil, seedCount: 8, closedRegistrationDate: nil, groupStageAdditionalQualified: 0, courtCount: 4, prioritizeClubMembers: false, qualifiedPerGroupStage: 2, teamsPerGroupStage: 4, entryFee: nil) + return Tournament(event: "Roland Garros", name: "Magic P100", startDate: Date(), endDate: Date(), creationDate: Date(), isPrivate: false, groupStageFormat: .nineGames, roundFormat: nil, loserRoundFormat: nil, groupStageSortMode: .snake, groupStageCount: 4, rankSourceDate: nil, dayDuration: 2, teamCount: 24, teamSorting: .rank, federalCategory: .men, federalLevelCategory: .p100, federalAgeCategory: .a45, groupStageCourtCount: nil, closedRegistrationDate: nil, groupStageAdditionalQualified: 0, courtCount: 4, prioritizeClubMembers: false, qualifiedPerGroupStage: 2, teamsPerGroupStage: 4, entryFee: nil) } } diff --git a/PadelClub/Data/User.swift b/PadelClub/Data/User.swift index 96e2e49..1626594 100644 --- a/PadelClub/Data/User.swift +++ b/PadelClub/Data/User.swift @@ -27,15 +27,6 @@ class User: UserBase { var lastName: String var phone: String? var country: String? - var callMessageBody : String? = nil - var callMessageSignature: String? = nil - var callDisplayFormat: Bool = false - var callDisplayEntryFee: Bool = false - var callUseFullCustomMessage: Bool = false - var matchFormatsDefaultDuration: [MatchFormat: Int]? = nil - var bracketMatchFormatPreference: MatchFormat? - var groupStageMatchFormatPreference: MatchFormat? - var loserBracketMatchFormatPreference: MatchFormat? init(username: String, email: String, firstName: String, lastName: String, phone: String?, country: String?) { self.username = username @@ -73,15 +64,6 @@ class User: UserBase { case _lastName = "lastName" case _phone = "phone" case _country = "country" - case _callMessageBody = "callMessageBody" - case _callMessageSignature = "callMessageSignature" - case _callDisplayFormat = "callDisplayFormat" - case _callDisplayEntryFee = "callDisplayEntryFee" - case _callUseFullCustomMessage = "callUseFullCustomMessage" - case _matchFormatsDefaultDuration = "matchFormatsDefaultDuration" - case _bracketMatchFormatPreference = "bracketMatchFormatPreference" - case _groupStageMatchFormatPreference = "groupStageMatchFormatPreference" - case _loserBracketMatchFormatPreference = "loserBracketMatchFormatPreference" } } diff --git a/PadelClub/ViewModel/AgendaDestination.swift b/PadelClub/ViewModel/AgendaDestination.swift index ba19f71..18982e8 100644 --- a/PadelClub/ViewModel/AgendaDestination.swift +++ b/PadelClub/ViewModel/AgendaDestination.swift @@ -61,6 +61,8 @@ enum AgendaDestination: CaseIterable, Identifiable, Selectable { switch self { case .history: return .green + case .tenup: + return .logoBackground default: return nil } diff --git a/PadelClub/Views/Player/Components/PlayerPopoverView.swift b/PadelClub/Views/Player/Components/PlayerPopoverView.swift index 10da49b..18974c1 100644 --- a/PadelClub/Views/Player/Components/PlayerPopoverView.swift +++ b/PadelClub/Views/Player/Components/PlayerPopoverView.swift @@ -246,7 +246,7 @@ struct PlayerPopoverView: View { } func createManualPlayer() { - let playerRegistration = PlayerRegistration(firstName: firstName, lastName: lastName, licenceId: license.trimmed.isEmpty ? nil : license, rank: rank, sex: sex) + let playerRegistration = PlayerRegistration(firstName: firstName, lastName: lastName, licenceId: license.trimmed.isEmpty ? nil : license, rank: rank, sex: PlayerRegistration.PlayerSexType(rawValue: sex)) self.creationCompletionHandler(playerRegistration) } diff --git a/PadelClub/Views/Player/Components/PlayerSexPickerView.swift b/PadelClub/Views/Player/Components/PlayerSexPickerView.swift index e3b3d38..b81e27e 100644 --- a/PadelClub/Views/Player/Components/PlayerSexPickerView.swift +++ b/PadelClub/Views/Player/Components/PlayerSexPickerView.swift @@ -17,8 +17,8 @@ struct PlayerSexPickerView: View { Text(player.playerLabel()) Spacer() Picker(selection: $player.sex) { - Text("Homme").tag(1 as Int) - Text("Femme").tag(0 as Int) + Text("Homme").tag(PlayerRegistration.PlayerSexType.male) + Text("Femme").tag(PlayerRegistration.PlayerSexType.female) } label: { } diff --git a/PadelClub/Views/Tournament/Screen/Components/InscriptionInfoView.swift b/PadelClub/Views/Tournament/Screen/Components/InscriptionInfoView.swift index 8b95ae2..24f6eeb 100644 --- a/PadelClub/Views/Tournament/Screen/Components/InscriptionInfoView.swift +++ b/PadelClub/Views/Tournament/Screen/Components/InscriptionInfoView.swift @@ -20,7 +20,7 @@ struct InscriptionInfoView: View { var waitingList : [TeamRegistration] { tournament.waitingListTeams(in: selectedTeams) } var duplicates : [PlayerRegistration] { tournament.duplicates(in: players) } - var problematicPlayers : [PlayerRegistration] { players.filter({ $0.sex == -1 }) } + var problematicPlayers : [PlayerRegistration] { players.filter({ $0.sex == nil }) } var inadequatePlayers : [PlayerRegistration] { tournament.inadequatePlayers(in: players) } var playersWithoutValidLicense : [PlayerRegistration] { tournament.playersWithoutValidLicense(in: players) } var entriesFromBeachPadel : [TeamRegistration] { tournament.unsortedTeams().filter({ $0.isImported() }) }