diff --git a/PadelClub/Data/GroupStage.swift b/PadelClub/Data/GroupStage.swift index 690552f..4e69732 100644 --- a/PadelClub/Data/GroupStage.swift +++ b/PadelClub/Data/GroupStage.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 { diff --git a/PadelClub/Data/Match.swift b/PadelClub/Data/Match.swift index 62a2d40..e31d4b8 100644 --- a/PadelClub/Data/Match.swift +++ b/PadelClub/Data/Match.swift @@ -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 } diff --git a/PadelClub/Data/MatchScheduler.swift b/PadelClub/Data/MatchScheduler.swift index 24d8ea5..cda8c45 100644 --- a/PadelClub/Data/MatchScheduler.swift +++ b/PadelClub/Data/MatchScheduler.swift @@ -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) + } } diff --git a/PadelClub/Data/MonthData.swift b/PadelClub/Data/MonthData.swift index 0dcd8e8..907cdcb 100644 --- a/PadelClub/Data/MonthData.swift +++ b/PadelClub/Data/MonthData.swift @@ -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) + } } } } diff --git a/PadelClub/Data/Round.swift b/PadelClub/Data/Round.swift index 1abc4aa..a2eddb9 100644 --- a/PadelClub/Data/Round.swift +++ b/PadelClub/Data/Round.swift @@ -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.., 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 diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index ec95afd..9b4c985 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -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..