update apischedule public func

update try? to try catch
multistore
Razmig Sarkissian 1 year ago
parent 7fdfb0aec2
commit 41650dfa90
  1. 6
      PadelClub/Data/GroupStage.swift
  2. 56
      PadelClub/Data/Match.swift
  3. 24
      PadelClub/Data/MatchScheduler.swift
  4. 6
      PadelClub/Data/MonthData.swift
  5. 26
      PadelClub/Data/Round.swift
  6. 6
      PadelClub/Data/TeamRegistration.swift
  7. 60
      PadelClub/Data/Tournament.swift
  8. 12
      PadelClub/Views/Calling/CallSettingsView.swift
  9. 7
      PadelClub/Views/Calling/CallView.swift
  10. 13
      PadelClub/Views/Cashier/CashierSettingsView.swift
  11. 19
      PadelClub/Views/Club/CourtView.swift
  12. 7
      PadelClub/Views/GroupStage/Components/GroupStageTeamView.swift
  13. 6
      PadelClub/Views/GroupStage/GroupStageSettingsView.swift
  14. 7
      PadelClub/Views/Match/MatchDetailView.swift
  15. 67
      PadelClub/Views/Match/MatchSetupView.swift
  16. 7
      PadelClub/Views/Navigation/Agenda/CalendarView.swift
  17. 30
      PadelClub/Views/Navigation/Toolbox/ToolboxView.swift
  18. 31
      PadelClub/Views/Planning/CourtAvailabilitySettingsView.swift
  19. 7
      PadelClub/Views/Planning/GroupStageScheduleEditorView.swift
  20. 7
      PadelClub/Views/Planning/LoserRoundScheduleEditorView.swift
  21. 7
      PadelClub/Views/Planning/LoserRoundStepScheduleEditorView.swift
  22. 7
      PadelClub/Views/Planning/RoundScheduleEditorView.swift
  23. 25
      PadelClub/Views/Player/Components/EditablePlayerView.swift
  24. 7
      PadelClub/Views/Player/Components/PlayerPayView.swift
  25. 13
      PadelClub/Views/Player/PlayerDetailView.swift
  26. 7
      PadelClub/Views/Player/PlayerView.swift
  27. 24
      PadelClub/Views/Round/RoundSettingsView.swift
  28. 13
      PadelClub/Views/Round/RoundView.swift
  29. 7
      PadelClub/Views/Team/EditingTeamView.swift
  30. 6
      PadelClub/Views/Tournament/FileImportView.swift
  31. 12
      PadelClub/Views/Tournament/Screen/Components/TournamentMatchFormatsSettingsView.swift
  32. 48
      PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift

@ -233,7 +233,11 @@ class GroupStage: ModelObject, Storable {
}
private func _removeMatches() {
try? DataStore.shared.matches.delete(contentOfs: _matches())
do {
try DataStore.shared.matches.delete(contentOfs: _matches())
} catch {
Logger.error(error)
}
}
private func _numberOfMatchesToBuild() -> Int {

@ -184,15 +184,27 @@ class Match: ModelObject, Storable {
func teamWillBeWalkOut(_ team: TeamRegistration) {
resetMatch()
let previousScores = teamScores.filter({ $0.luckyLoser != nil })
try? DataStore.shared.teamScores.delete(contentOfs: previousScores)
do {
try DataStore.shared.teamScores.delete(contentOfs: previousScores)
} catch {
Logger.error(error)
}
if let existingTeamScore = teamScore(ofTeam: team) {
try? DataStore.shared.teamScores.delete(instance: existingTeamScore)
do {
try DataStore.shared.teamScores.delete(instance: existingTeamScore)
} catch {
Logger.error(error)
}
}
let teamScoreWalkout = TeamScore(match: id, team: team)
teamScoreWalkout.walkOut = 1
try? DataStore.shared.teamScores.addOrUpdate(instance: teamScoreWalkout)
do {
try DataStore.shared.teamScores.addOrUpdate(instance: teamScoreWalkout)
} catch {
Logger.error(error)
}
}
func luckyLosers() -> [TeamRegistration] {
@ -206,17 +218,29 @@ class Match: ModelObject, Storable {
func setLuckyLoser(team: TeamRegistration, teamPosition: TeamPosition) {
resetMatch()
let previousScores = teamScores.filter({ $0.luckyLoser != nil })
try? DataStore.shared.teamScores.delete(contentOfs: previousScores)
do {
try DataStore.shared.teamScores.delete(contentOfs: previousScores)
} catch {
Logger.error(error)
}
if let existingTeamScore = teamScore(ofTeam: team) {
try? DataStore.shared.teamScores.delete(instance: existingTeamScore)
do {
try DataStore.shared.teamScores.delete(instance: existingTeamScore)
} catch {
Logger.error(error)
}
}
let matchIndex = index
let position = matchIndex * 2 + teamPosition.rawValue
let teamScoreLuckyLoser = TeamScore(match: id, team: team)
teamScoreLuckyLoser.luckyLoser = position
try? DataStore.shared.teamScores.addOrUpdate(instance: teamScoreLuckyLoser)
do {
try DataStore.shared.teamScores.addOrUpdate(instance: teamScoreLuckyLoser)
} catch {
Logger.error(error)
}
}
func disableMatch() {
@ -299,8 +323,12 @@ class Match: ModelObject, Storable {
//if disabled == state { return }
disabled = state
//byeState = false
//try? DataStore.shared.matches.addOrUpdate(instance: self)
do {
try DataStore.shared.matches.addOrUpdate(instance: self)
} catch {
Logger.error(error)
}
_toggleLoserMatchDisableState(state)
if forward {
_toggleForwardMatchDisableState(state)
@ -403,7 +431,11 @@ class Match: ModelObject, Storable {
teamScoreWalkout.walkOut = 0
let teamScoreWinning = teamScore(teamPosition.otherTeam) ?? TeamScore(match: id, team: team(teamPosition.otherTeam))
teamScoreWinning.walkOut = nil
try? DataStore.shared.teamScores.addOrUpdate(contentOfs: [teamScoreWalkout, teamScoreWinning])
do {
try DataStore.shared.teamScores.addOrUpdate(contentOfs: [teamScoreWalkout, teamScoreWinning])
} catch {
Logger.error(error)
}
if endDate == nil {
endDate = Date()
@ -433,7 +465,11 @@ class Match: ModelObject, Storable {
teamScoreOne.score = matchDescriptor.teamOneScores.joined(separator: ",")
let teamScoreTwo = teamScore(.two) ?? TeamScore(match: id, team: team(.two))
teamScoreTwo.score = matchDescriptor.teamTwoScores.joined(separator: ",")
try? DataStore.shared.teamScores.addOrUpdate(contentOfs: [teamScoreOne, teamScoreTwo])
do {
try DataStore.shared.teamScores.addOrUpdate(contentOfs: [teamScoreOne, teamScoreTwo])
} catch {
Logger.error(error)
}
matchFormat = matchDescriptor.matchFormat
}

@ -98,7 +98,11 @@ class MatchScheduler : ModelObject, Storable {
if let first = times.first {
if first.isEarlierThan(tournament.startDate) {
tournament.startDate = first
try? DataStore.shared.tournaments.addOrUpdate(instance: tournament)
do {
try DataStore.shared.tournaments.addOrUpdate(instance: tournament)
} catch {
Logger.error(error)
}
}
}
@ -123,7 +127,11 @@ class MatchScheduler : ModelObject, Storable {
groupStages.filter({ $0.startDate == nil || times.contains($0.startDate!) == false }).chunked(into: computedGroupStageChunkCount).forEach { groups in
groups.forEach({ $0.startDate = lastDate })
try? DataStore.shared.groupStages.addOrUpdate(contentOfs: groups)
do {
try DataStore.shared.groupStages.addOrUpdate(contentOfs: groups)
} catch {
Logger.error(error)
}
let dispatch = groupStageDispatcher(numberOfCourtsAvailablePerRotation: numberOfCourtsAvailablePerRotation, groupStages: groups, startingDate: lastDate)
@ -140,7 +148,11 @@ class MatchScheduler : ModelObject, Storable {
}
}
}
try? DataStore.shared.matches.addOrUpdate(contentOfs: matches)
do {
try DataStore.shared.matches.addOrUpdate(contentOfs: matches)
} catch {
Logger.error(error)
}
return lastDate
}
@ -609,7 +621,11 @@ class MatchScheduler : ModelObject, Storable {
}
}
try? DataStore.shared.matches.addOrUpdate(contentOfs: allMatches)
do {
try DataStore.shared.matches.addOrUpdate(contentOfs: allMatches)
} catch {
Logger.error(error)
}
}

@ -47,7 +47,11 @@ class MonthData : ModelObject, Storable {
currentMonthData.femaleUnrankedValue = lastDataSourceFemaleUnranked?.0
currentMonthData.femaleCount = lastDataSourceFemaleUnranked?.1
currentMonthData.anonymousCount = anonymousCount
try? DataStore.shared.monthData.addOrUpdate(instance: currentMonthData)
do {
try DataStore.shared.monthData.addOrUpdate(instance: currentMonthData)
} catch {
Logger.error(error)
}
}
}
}

@ -281,9 +281,17 @@ class Round: ModelObject, Storable {
_matches.forEach { match in
match.disabled = disable
match.resetMatch()
try? DataStore.shared.teamScores.delete(contentOfs: match.teamScores)
do {
try DataStore.shared.teamScores.delete(contentOfs: match.teamScores)
} catch {
Logger.error(error)
}
}
do {
try DataStore.shared.matches.addOrUpdate(contentOfs: _matches)
} catch {
Logger.error(error)
}
try? DataStore.shared.matches.addOrUpdate(contentOfs: _matches)
}
var cumulativeMatchCount: Int {
@ -425,7 +433,11 @@ class Round: ModelObject, Storable {
return round
}
try? DataStore.shared.rounds.addOrUpdate(contentOfs: rounds)
do {
try DataStore.shared.rounds.addOrUpdate(contentOfs: rounds)
} catch {
Logger.error(error)
}
let matchCount = RoundRule.numberOfMatches(forTeams: currentRoundMatchCount)
let matches = (0..<matchCount).map { //0 is final match
@ -434,8 +446,12 @@ class Round: ModelObject, Storable {
return Match(round: round.id, index: $0, matchFormat: loserBracketMatchFormat, name: round.roundTitle())
}
try? DataStore.shared.matches.addOrUpdate(contentOfs: matches)
do {
try DataStore.shared.matches.addOrUpdate(contentOfs: matches)
} catch {
Logger.error(error)
}
loserRounds().forEach { round in
round.buildLoserBracket()
}

@ -216,7 +216,11 @@ class TeamRegistration: ModelObject, Storable {
func updatePlayers(_ players: Set<PlayerRegistration>, inTournamentCategory tournamentCategory: TournamentCategory) {
try? DataStore.shared.playerRegistrations.delete(contentOfs: unsortedPlayers())
do {
try DataStore.shared.playerRegistrations.delete(contentOfs: unsortedPlayers())
} catch {
Logger.error(error)
}
setWeight(from: Array(players), inTournamentCategory: tournamentCategory)
players.forEach { player in

@ -886,8 +886,16 @@ class Tournament : ModelObject, Storable {
}
}
try? DataStore.shared.teamRegistrations.addOrUpdate(contentOfs: teamsToImport)
try? DataStore.shared.playerRegistrations.addOrUpdate(contentOfs: teams.flatMap { $0.players })
do {
try DataStore.shared.teamRegistrations.addOrUpdate(contentOfs: teamsToImport)
} catch {
Logger.error(error)
}
do {
try DataStore.shared.playerRegistrations.addOrUpdate(contentOfs: teams.flatMap { $0.players })
} catch {
Logger.error(error)
}
}
@ -998,7 +1006,11 @@ class Tournament : ModelObject, Storable {
teams.forEach { team in
team.lockedWeight = team.weight
}
try? DataStore.shared.teamRegistrations.addOrUpdate(contentOfs: teams)
do {
try DataStore.shared.teamRegistrations.addOrUpdate(contentOfs: teams)
} catch {
Logger.error(error)
}
}
func updateWeights() {
@ -1007,9 +1019,17 @@ class Tournament : ModelObject, Storable {
let players = team.unsortedPlayers()
players.forEach { $0.setComputedRank(in: self) }
team.setWeight(from: players, inTournamentCategory: tournamentCategory)
try? DataStore.shared.playerRegistrations.addOrUpdate(contentOfs: players)
do {
try DataStore.shared.playerRegistrations.addOrUpdate(contentOfs: players)
} catch {
Logger.error(error)
}
}
do {
try DataStore.shared.teamRegistrations.addOrUpdate(contentOfs: teams)
} catch {
Logger.error(error)
}
try? DataStore.shared.teamRegistrations.addOrUpdate(contentOfs: teams)
}
func updateRank(to newDate: Date?) async throws {
@ -1023,7 +1043,11 @@ class Tournament : ModelObject, Storable {
let monthData = MonthData(monthKey: URL.importDateFormatter.string(from: newDate))
monthData.maleUnrankedValue = lastRankMan
monthData.femaleUnrankedValue = lastRankWoman
try? DataStore.shared.monthData.addOrUpdate(instance: monthData)
do {
try DataStore.shared.monthData.addOrUpdate(instance: monthData)
} catch {
Logger.error(error)
}
}
}
@ -1232,7 +1256,11 @@ class Tournament : ModelObject, Storable {
_groupStages.append(groupStage)
}
try? DataStore.shared.groupStages.addOrUpdate(contentOfs: _groupStages)
do {
try DataStore.shared.groupStages.addOrUpdate(contentOfs: _groupStages)
} catch {
Logger.error(error)
}
refreshGroupStages()
}
@ -1250,7 +1278,11 @@ class Tournament : ModelObject, Storable {
Round(tournament: id, index: $0)
}
try? DataStore.shared.rounds.addOrUpdate(contentOfs: rounds)
do {
try DataStore.shared.rounds.addOrUpdate(contentOfs: rounds)
} catch {
Logger.error(error)
}
let matchCount = RoundRule.numberOfMatches(forTeams: bracketTeamCount())
let matches = (0..<matchCount).map { //0 is final match
@ -1263,7 +1295,11 @@ class Tournament : ModelObject, Storable {
(RoundRule.roundName(fromMatchIndex: $0.index), RoundRule.matchIndexWithinRound(fromMatchIndex: $0.index))
})
try? DataStore.shared.matches.addOrUpdate(contentOfs: matches)
do {
try DataStore.shared.matches.addOrUpdate(contentOfs: matches)
} catch {
Logger.error(error)
}
self.rounds().forEach { round in
round.buildLoserBracket()
@ -1364,7 +1400,11 @@ class Tournament : ModelObject, Storable {
chunks[index][jIndex].groupStage = groupStages[jIndex].id
chunks[index][jIndex].groupStagePosition = index
try? DataStore.shared.teamRegistrations.addOrUpdate(instance: chunks[index][jIndex])
do {
try DataStore.shared.teamRegistrations.addOrUpdate(instance: chunks[index][jIndex])
} catch {
Logger.error(error)
}
}
}

@ -58,7 +58,11 @@ struct CallSettingsView: View {
teams.forEach { team in
team.callDate = nil
}
try? dataStore.teamRegistrations.addOrUpdate(contentOfs: teams)
do {
try dataStore.teamRegistrations.addOrUpdate(contentOfs: teams)
} catch {
Logger.error(error)
}
}
}
@ -68,7 +72,11 @@ struct CallSettingsView: View {
teams.forEach { team in
team.callDate = team.expectedSummonDate()
}
try? dataStore.teamRegistrations.addOrUpdate(contentOfs: teams)
do {
try dataStore.teamRegistrations.addOrUpdate(contentOfs: teams)
} catch {
Logger.error(error)
}
}
}
#endif

@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct CallView: View {
@ -76,7 +77,11 @@ struct CallView: View {
teams.forEach { team in
team.callDate = callDate
}
try? dataStore.teamRegistrations.addOrUpdate(contentOfs: teams)
do {
try dataStore.teamRegistrations.addOrUpdate(contentOfs: teams)
} catch {
Logger.error(error)
}
}
}

@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct CashierSettingsView: View {
@EnvironmentObject var dataStore: DataStore
@ -29,7 +30,11 @@ struct CashierSettingsView: View {
player.paymentType = .gift
}
}
try? dataStore.playerRegistrations.addOrUpdate(contentOfs: players)
do {
try dataStore.playerRegistrations.addOrUpdate(contentOfs: players)
} catch {
Logger.error(error)
}
}
} footer: {
Text("Passe tous les joueurs qui n'ont pas réglé en offert")
@ -41,7 +46,11 @@ struct CashierSettingsView: View {
players.forEach { player in
player.paymentType = nil
}
try? dataStore.playerRegistrations.addOrUpdate(contentOfs: players)
do {
try dataStore.playerRegistrations.addOrUpdate(contentOfs: players)
} catch {
Logger.error(error)
}
}
} footer: {
Text("Remet à zéro le type d'encaissement de tous les joueurs")

@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct CourtView: View {
@EnvironmentObject var dataStore: DataStore
@ -31,7 +32,11 @@ struct CourtView: View {
if name.isEmpty {
court.name = nil
}
try? dataStore.courts.addOrUpdate(instance: court)
do {
try dataStore.courts.addOrUpdate(instance: court)
} catch {
Logger.error(error)
}
}
} label: {
Text("Nom du terrain")
@ -41,7 +46,11 @@ struct CourtView: View {
FooterButtonView("nom par défaut") {
name = ""
court.name = nil
try? dataStore.courts.addOrUpdate(instance: court)
do {
try dataStore.courts.addOrUpdate(instance: court)
} catch {
Logger.error(error)
}
}
}
}
@ -56,7 +65,11 @@ struct CourtView: View {
}
}
.onChange(of: [court.indoor, court.exitAllowed]) {
try? dataStore.courts.addOrUpdate(instance: court)
do {
try dataStore.courts.addOrUpdate(instance: court)
} catch {
Logger.error(error)
}
}
.navigationTitle(court.courtTitle())
.navigationBarTitleDisplayMode(.inline)

@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct GroupStageTeamView: View {
@EnvironmentObject var dataStore: DataStore
@ -83,7 +84,11 @@ struct GroupStageTeamView: View {
}
private func _save() {
try? dataStore.teamRegistrations.addOrUpdate(instance: team)
do {
try dataStore.teamRegistrations.addOrUpdate(instance: team)
} catch {
Logger.error(error)
}
dismiss()
}
}

@ -82,7 +82,11 @@ struct GroupStageSettingsView: View {
groupStage.name = nil
}
}
try? dataStore.groupStages.addOrUpdate(contentOfs: groupStages)
do {
try dataStore.groupStages.addOrUpdate(contentOfs: groupStages)
} catch {
Logger.error(error)
}
}
}

@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct MatchDetailView: View {
@EnvironmentObject var dataStore: DataStore
@ -447,7 +448,11 @@ struct MatchDetailView: View {
private func save() {
try? dataStore.matches.addOrUpdate(instance: match)
do {
try dataStore.matches.addOrUpdate(instance: match)
} catch {
Logger.error(error)
}
}
}

@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct MatchSetupView: View {
@EnvironmentObject var dataStore: DataStore
@ -36,11 +37,23 @@ struct MatchSetupView: View {
team.bracketPosition = nil
match.updateTeamScores()
match.enableMatch()
try? dataStore.matches.addOrUpdate(instance: match)
try? dataStore.teamRegistrations.addOrUpdate(instance: team)
do {
try dataStore.matches.addOrUpdate(instance: match)
} catch {
Logger.error(error)
}
do {
try dataStore.teamRegistrations.addOrUpdate(instance: team)
} catch {
Logger.error(error)
}
} else {
match.teamWillBeWalkOut(team)
try? dataStore.matches.addOrUpdate(instance: match)
do {
try dataStore.matches.addOrUpdate(instance: match)
} catch {
Logger.error(error)
}
}
} label: {
Label("retirer", systemImage: "xmark")
@ -60,11 +73,23 @@ struct MatchSetupView: View {
print(team.pasteData())
if walkOutSpot {
match.setLuckyLoser(team: team, teamPosition: teamPosition)
try? dataStore.matches.addOrUpdate(instance: match)
do {
try dataStore.matches.addOrUpdate(instance: match)
} catch {
Logger.error(error)
}
} else {
team.setSeedPosition(inSpot: match, slot: teamPosition, opposingSeeding: false)
try? dataStore.matches.addOrUpdate(instance: match)
try? dataStore.teamRegistrations.addOrUpdate(instance: team)
do {
try dataStore.matches.addOrUpdate(instance: match)
} catch {
Logger.error(error)
}
do {
try dataStore.teamRegistrations.addOrUpdate(instance: team)
} catch {
Logger.error(error)
}
}
})
if let tournament = match.currentTournament() {
@ -75,7 +100,11 @@ struct MatchSetupView: View {
Button {
if let randomTeam = luckyLosers.randomElement() {
match.setLuckyLoser(team: randomTeam, teamPosition: teamPosition)
try? dataStore.matches.addOrUpdate(instance: match)
do {
try dataStore.matches.addOrUpdate(instance: match)
} catch {
Logger.error(error)
}
}
} label: {
Label("Repêchage", systemImage: "dice")
@ -85,8 +114,16 @@ struct MatchSetupView: View {
Button {
if let randomTeam = tournament.randomSeed(fromSeedGroup: seedGroup) {
randomTeam.setSeedPosition(inSpot: match, slot: teamPosition, opposingSeeding: false)
try? dataStore.matches.addOrUpdate(instance: match)
try? dataStore.teamRegistrations.addOrUpdate(instance: randomTeam)
do {
try dataStore.matches.addOrUpdate(instance: match)
} catch {
Logger.error(error)
}
do {
try dataStore.teamRegistrations.addOrUpdate(instance: randomTeam)
} catch {
Logger.error(error)
}
}
} label: {
Label(seedGroup.localizedLabel(), systemImage: "dice")
@ -101,7 +138,11 @@ struct MatchSetupView: View {
if match.isSeedLocked(atTeamPosition: teamPosition) {
Button {
match.unlockSeedPosition(atTeamPosition: teamPosition)
try? dataStore.matches.addOrUpdate(instance: match)
do {
try dataStore.matches.addOrUpdate(instance: match)
} catch {
Logger.error(error)
}
} label: {
Text("Libérer")
.underline()
@ -109,7 +150,11 @@ struct MatchSetupView: View {
} else {
Button {
_ = match.lockAndGetSeedPosition(atTeamPosition: teamPosition)
try? dataStore.matches.addOrUpdate(instance: match)
do {
try dataStore.matches.addOrUpdate(instance: match)
} catch {
Logger.error(error)
}
} label: {
Text("Réserver")
.underline()

@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct CalendarView: View {
@EnvironmentObject var dataStore: DataStore
@ -164,7 +165,11 @@ struct CalendarView: View {
newTournament.dayDuration = federalTournament.dayDuration
newTournament.startDate = federalTournament.startDate.atBeginningOfDay(hourInt: 9)
newTournament.setupFederalSettings()
try? dataStore.tournaments.addOrUpdate(instance: newTournament)
do {
try dataStore.tournaments.addOrUpdate(instance: newTournament)
} catch {
Logger.error(error)
}
navigation.path.append(newTournament)
}
}

@ -17,21 +17,21 @@ struct ToolboxView: View {
NavigationStack(path: $navigation.toolboxPath) {
List {
#if DEBUG
// Section {
// RowButtonView("Reset ALL API Calls") {
// dataStore.courts.resetApiCalls()
// dataStore.matches.resetApiCalls()
// dataStore.tournaments.resetApiCalls()
// dataStore.teamRegistrations.resetApiCalls()
// dataStore.playerRegistrations.resetApiCalls()
// dataStore.teamScores.resetApiCalls()
// dataStore.rounds.resetApiCalls()
// dataStore.groupStages.resetApiCalls()
// dataStore.clubs.resetApiCalls()
// dataStore.events.resetApiCalls()
// dataStore.dateIntervals.resetApiCalls()
// }
// }
Section {
RowButtonView("Reset ALL API Calls") {
dataStore.courts.resetApiCalls()
dataStore.matches.resetApiCalls()
dataStore.tournaments.resetApiCalls()
dataStore.teamRegistrations.resetApiCalls()
dataStore.playerRegistrations.resetApiCalls()
dataStore.teamScores.resetApiCalls()
dataStore.rounds.resetApiCalls()
dataStore.groupStages.resetApiCalls()
dataStore.clubs.resetApiCalls()
dataStore.events.resetApiCalls()
dataStore.dateIntervals.resetApiCalls()
}
}
Section {
RowButtonView("Fix Names") {
let playerRegistrations = dataStore.playerRegistrations

@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct CourtAvailabilitySettingsView: View {
@Environment(Tournament.self) var tournament: Tournament
@ -36,7 +37,11 @@ struct CourtAvailabilitySettingsView: View {
Menu {
Button("dupliquer") {
let duplicatedDateInterval = DateInterval(event: event.id, courtIndex: (courtIndex+1)%tournament.courtCount, startDate: dateInterval.startDate, endDate: dateInterval.endDate)
try? dataStore.dateIntervals.addOrUpdate(instance: duplicatedDateInterval)
do {
try dataStore.dateIntervals.addOrUpdate(instance: duplicatedDateInterval)
} catch {
Logger.error(error)
}
}
Button("éditer") {
editingSlot = dateInterval
@ -46,7 +51,11 @@ struct CourtAvailabilitySettingsView: View {
showingPopover = true
}
Button("effacer", role: .destructive) {
try? dataStore.dateIntervals.delete(instance: dateInterval)
do {
try dataStore.dateIntervals.delete(instance: dateInterval)
} catch {
Logger.error(error)
}
}
} label: {
HStack {
@ -69,7 +78,11 @@ struct CourtAvailabilitySettingsView: View {
}
.swipeActions {
Button(role: .destructive) {
try? dataStore.dateIntervals.delete(instance: dateInterval)
do {
try dataStore.dateIntervals.delete(instance: dateInterval)
} catch {
Logger.error(error)
}
} label: {
LabelDelete()
}
@ -136,12 +149,20 @@ struct CourtAvailabilitySettingsView: View {
ButtonValidateView {
if editingSlot == nil {
let dateInterval = DateInterval(event: event.id, courtIndex: courtIndex, startDate: startDate, endDate: endDate)
try? dataStore.dateIntervals.addOrUpdate(instance: dateInterval)
do {
try dataStore.dateIntervals.addOrUpdate(instance: dateInterval)
} catch {
Logger.error(error)
}
} else {
editingSlot?.courtIndex = courtIndex
editingSlot?.endDate = endDate
editingSlot?.startDate = startDate
try? dataStore.dateIntervals.addOrUpdate(instance: editingSlot!)
do {
try dataStore.dateIntervals.addOrUpdate(instance: editingSlot!)
} catch {
Logger.error(error)
}
}
showingPopover = false
}

@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct GroupStageScheduleEditorView: View {
@EnvironmentObject var dataStore: DataStore
@ -27,7 +28,11 @@ struct GroupStageScheduleEditorView: View {
}
private func _save() {
try? dataStore.groupStages.addOrUpdate(instance: groupStage)
do {
try dataStore.groupStages.addOrUpdate(instance: groupStage)
} catch {
Logger.error(error)
}
}
}

@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct LoserRoundScheduleEditorView: View {
@EnvironmentObject var dataStore: DataStore
@ -72,7 +73,11 @@ struct LoserRoundScheduleEditorView: View {
}
private func _save() {
try? dataStore.rounds.addOrUpdate(contentOfs: upperRound.loserRounds())
do {
try dataStore.rounds.addOrUpdate(contentOfs: upperRound.loserRounds())
} catch {
Logger.error(error)
}
}
}

@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct LoserRoundStepScheduleEditorView: View {
@EnvironmentObject var dataStore: DataStore
@ -67,6 +68,10 @@ struct LoserRoundStepScheduleEditorView: View {
}
private func _save() {
try? dataStore.rounds.addOrUpdate(contentOfs: upperRound.loserRounds(forRoundIndex: round.index))
do {
try dataStore.rounds.addOrUpdate(contentOfs: upperRound.loserRounds(forRoundIndex: round.index))
} catch {
Logger.error(error)
}
}
}

@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct RoundScheduleEditorView: View {
@EnvironmentObject var dataStore: DataStore
@ -60,7 +61,11 @@ struct RoundScheduleEditorView: View {
}
private func _save() {
try? dataStore.rounds.addOrUpdate(instance: round)
do {
try dataStore.rounds.addOrUpdate(instance: round)
} catch {
Logger.error(error)
}
}
}

@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct EditablePlayerView: View {
@ -30,19 +31,31 @@ struct EditablePlayerView: View {
.onSubmit {
player.licenceId = editedLicenceId
editedLicenceId = ""
try? dataStore.playerRegistrations.addOrUpdate(instance: player)
do {
try dataStore.playerRegistrations.addOrUpdate(instance: player)
} catch {
Logger.error(error)
}
}
}
.alert("Prénom", isPresented: $presentFirstNameUpdate) {
TextField("Prénom", text: $player.firstName)
.onSubmit {
try? dataStore.playerRegistrations.addOrUpdate(instance: player)
do {
try dataStore.playerRegistrations.addOrUpdate(instance: player)
} catch {
Logger.error(error)
}
}
}
.alert("Nom", isPresented: $presentLastNameUpdate) {
TextField("Nom", text: $player.lastName)
.onSubmit {
try? dataStore.playerRegistrations.addOrUpdate(instance: player)
do {
try dataStore.playerRegistrations.addOrUpdate(instance: player)
} catch {
Logger.error(error)
}
}
}
@ -61,7 +74,11 @@ struct EditablePlayerView: View {
Menu {
Button {
player.hasArrived.toggle()
try? dataStore.playerRegistrations.addOrUpdate(instance: player)
do {
try dataStore.playerRegistrations.addOrUpdate(instance: player)
} catch {
Logger.error(error)
}
} label: {
Label("Présent", systemImage: player.hasArrived ? "checkmark.circle" : "circle")
}

@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct PlayerPayView: View {
@EnvironmentObject var dataStore: DataStore
@ -27,6 +28,10 @@ struct PlayerPayView: View {
}
private func _save() {
try? dataStore.playerRegistrations.addOrUpdate(instance: player)
do {
try dataStore.playerRegistrations.addOrUpdate(instance: player)
} catch {
Logger.error(error)
}
}
}

@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct PlayerDetailView: View {
@Environment(Tournament.self) var tournament: Tournament
@ -106,9 +107,17 @@ struct PlayerDetailView: View {
}
private func _save() {
try? dataStore.playerRegistrations.addOrUpdate(instance: player)
do {
try dataStore.playerRegistrations.addOrUpdate(instance: player)
} catch {
Logger.error(error)
}
if let team = player.team() {
try? dataStore.teamRegistrations.addOrUpdate(instance: team)
do {
try dataStore.teamRegistrations.addOrUpdate(instance: team)
} catch {
Logger.error(error)
}
}
}
}

@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct PlayerView: View {
@EnvironmentObject var dataStore: DataStore
@ -15,7 +16,11 @@ struct PlayerView: View {
ImportedPlayerView(player: player)
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
Button(role: .destructive) {
try? dataStore.playerRegistrations.delete(instance: player)
do {
try dataStore.playerRegistrations.delete(instance: player)
} catch {
Logger.error(error)
}
} label: {
LabelDelete()
}

@ -46,7 +46,11 @@ struct RoundSettingsView: View {
tournament.resetTeamScores(in: team.bracketPosition)
team.bracketPosition = nil
})
try? dataStore.teamRegistrations.addOrUpdate(contentOfs: tournament.unsortedTeams())
do {
try dataStore.teamRegistrations.addOrUpdate(contentOfs: tournament.unsortedTeams())
} catch {
Logger.error(error)
}
tournament.allRounds().forEach({ round in
round.enableRound()
})
@ -63,8 +67,16 @@ struct RoundSettingsView: View {
let matches = (0..<matchCount).map { //0 is final match
return Match(round: round.id, index: $0 + matchStartIndex, matchFormat: round.matchFormat, name: Match.setServerTitle(upperRound: round, matchIndex: $0))
}
try? dataStore.rounds.addOrUpdate(instance: round)
try? dataStore.matches.addOrUpdate(contentOfs: matches)
do {
try dataStore.rounds.addOrUpdate(instance: round)
} catch {
Logger.error(error)
}
do {
try dataStore.matches.addOrUpdate(contentOfs: matches)
} catch {
Logger.error(error)
}
round.buildLoserBracket()
}
}
@ -72,7 +84,11 @@ struct RoundSettingsView: View {
Section {
if let lastRound = tournament.rounds().first { // first is final, last round
RowButtonView("Supprimer " + lastRound.roundTitle(), role: .destructive) {
try? dataStore.rounds.delete(instance: lastRound)
do {
try dataStore.rounds.delete(instance: lastRound)
} catch {
Logger.error(error)
}
}
}
}

@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct RoundView: View {
@Environment(\.isEditingTournamentSeed) private var isEditingTournamentSeed
@ -132,7 +133,11 @@ struct RoundView: View {
}
private func _save() {
try? dataStore.teamRegistrations.addOrUpdate(contentOfs: tournament.unsortedTeams())
do {
try dataStore.teamRegistrations.addOrUpdate(contentOfs: tournament.unsortedTeams())
} catch {
Logger.error(error)
}
//todo should be done server side
let rounds = tournament.rounds()
@ -143,7 +148,11 @@ struct RoundView: View {
}
}
let allRoundMatches = tournament.allRoundMatches()
try? DataStore.shared.matches.addOrUpdate(contentOfs: allRoundMatches)
do {
try DataStore.shared.matches.addOrUpdate(contentOfs: allRoundMatches)
} catch {
Logger.error(error)
}
}
}

@ -6,6 +6,7 @@
//
import SwiftUI
import LeStorage
struct EditingTeamView: View {
@EnvironmentObject var dataStore: DataStore
@ -36,7 +37,11 @@ struct EditingTeamView: View {
}
private func _save() {
try? dataStore.teamRegistrations.addOrUpdate(instance: team)
do {
try dataStore.teamRegistrations.addOrUpdate(instance: team)
} catch {
Logger.error(error)
}
}
}

@ -233,7 +233,11 @@ struct FileImportView: View {
team.walkOut = true
}
try? dataStore.teamRegistrations.addOrUpdate(contentOfs: unfound)
do {
try dataStore.teamRegistrations.addOrUpdate(contentOfs: unfound)
} catch {
Logger.error(error)
}
}

@ -91,8 +91,16 @@ struct TournamentMatchFormatsSettingsView: View {
round.updateMatchFormatAndAllMatches(tournament.matchFormat)
}
}
try? dataStore.groupStages.addOrUpdate(contentOfs: groupStages)
try? dataStore.rounds.addOrUpdate(contentOfs: allRounds)
do {
try dataStore.groupStages.addOrUpdate(contentOfs: groupStages)
} catch {
Logger.error(error)
}
do {
try dataStore.rounds.addOrUpdate(contentOfs: allRounds)
} catch {
Logger.error(error)
}
confirmUpdate = false
updateCompleted = true

@ -744,8 +744,16 @@ struct InscriptionManagerView: View {
private func _createTeam() {
let players = _currentSelection()
let team = tournament.addTeam(players)
try? dataStore.teamRegistrations.addOrUpdate(instance: team)
try? dataStore.playerRegistrations.addOrUpdate(contentOfs: players)
do {
try dataStore.teamRegistrations.addOrUpdate(instance: team)
} catch {
Logger.error(error)
}
do {
try dataStore.playerRegistrations.addOrUpdate(contentOfs: players)
} catch {
Logger.error(error)
}
createdPlayers.removeAll()
createdPlayerIds.removeAll()
@ -756,8 +764,16 @@ struct InscriptionManagerView: View {
guard let editedTeam else { return }
let players = _currentSelection()
editedTeam.updatePlayers(players, inTournamentCategory: tournament.tournamentCategory)
try? dataStore.teamRegistrations.addOrUpdate(instance: editedTeam)
try? dataStore.playerRegistrations.addOrUpdate(contentOfs: players)
do {
try dataStore.teamRegistrations.addOrUpdate(instance: editedTeam)
} catch {
Logger.error(error)
}
do {
try dataStore.playerRegistrations.addOrUpdate(contentOfs: players)
} catch {
Logger.error(error)
}
createdPlayers.removeAll()
createdPlayerIds.removeAll()
pasteString = nil
@ -968,7 +984,11 @@ struct InscriptionManagerView: View {
team.wildCardGroupStage = false
team.walkOut = false
team.wildCardBracket = value
try? dataStore.teamRegistrations.addOrUpdate(instance: team)
do {
try dataStore.teamRegistrations.addOrUpdate(instance: team)
} catch {
Logger.error(error)
}
})) {
Label("Wildcard Tableau", systemImage: team.wildCardBracket ? "circle.inset.filled" : "circle")
}
@ -980,7 +1000,11 @@ struct InscriptionManagerView: View {
team.wildCardBracket = false
team.walkOut = false
team.wildCardGroupStage = value
try? dataStore.teamRegistrations.addOrUpdate(instance: team)
do {
try dataStore.teamRegistrations.addOrUpdate(instance: team)
} catch {
Logger.error(error)
}
})) {
Label("Wildcard Poule", systemImage: team.wildCardGroupStage ? "circle.inset.filled" : "circle")
}
@ -993,13 +1017,21 @@ struct InscriptionManagerView: View {
team.wildCardBracket = false
team.wildCardGroupStage = false
team.walkOut = value
try? dataStore.teamRegistrations.addOrUpdate(instance: team)
do {
try dataStore.teamRegistrations.addOrUpdate(instance: team)
} catch {
Logger.error(error)
}
})) {
Label("WO", systemImage: team.walkOut ? "circle.inset.filled" : "circle")
}
Divider()
Button(role: .destructive) {
try? dataStore.teamRegistrations.delete(instance: team)
do {
try dataStore.teamRegistrations.delete(instance: team)
} catch {
Logger.error(error)
}
} label: {
LabelDelete()
}

Loading…
Cancel
Save