From 2447930e60b1a0778cb0eee8bfb06d3b79cd5a5e Mon Sep 17 00:00:00 2001 From: Raz Date: Tue, 21 Jan 2025 19:30:09 +0100 Subject: [PATCH] fix player import stuff --- PadelClub/Data/TeamRegistration.swift | 24 ++++++++++++++++++++++- PadelClub/Views/Team/TeamDetailView.swift | 4 +++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/PadelClub/Data/TeamRegistration.swift b/PadelClub/Data/TeamRegistration.swift index cb14169..5a17734 100644 --- a/PadelClub/Data/TeamRegistration.swift +++ b/PadelClub/Data/TeamRegistration.swift @@ -433,6 +433,22 @@ final class TeamRegistration: ModelObject, Storable { func updatePlayers(_ players: Set, inTournamentCategory tournamentCategory: TournamentCategory) { let previousPlayers = Set(unsortedPlayers()) + + players.forEach { player in + previousPlayers.forEach { oldPlayer in + if player.licenceId?.strippedLicense == oldPlayer.licenceId?.strippedLicense, player.licenceId?.strippedLicense != nil { + player.registeredOnline = oldPlayer.registeredOnline + player.coach = oldPlayer.coach + player.tournamentPlayed = oldPlayer.tournamentPlayed + player.points = oldPlayer.points + player.captain = oldPlayer.captain + player.assimilation = oldPlayer.assimilation + player.ligueName = oldPlayer.ligueName + } + } + } + + let playersToRemove = previousPlayers.subtracting(players) do { try self.tournamentStore.playerRegistrations.delete(contentOfs: playersToRemove) @@ -443,7 +459,13 @@ final class TeamRegistration: ModelObject, Storable { players.forEach { player in player.teamRegistration = id - } + } + +// do { +// try self.tournamentStore.playerRegistrations.addOrUpdate(contentOfs: players) +// } catch { +// Logger.error(error) +// } } typealias TeamRange = (left: TeamRegistration?, right: TeamRegistration?) diff --git a/PadelClub/Views/Team/TeamDetailView.swift b/PadelClub/Views/Team/TeamDetailView.swift index 5c22e95..969731d 100644 --- a/PadelClub/Views/Team/TeamDetailView.swift +++ b/PadelClub/Views/Team/TeamDetailView.swift @@ -24,7 +24,9 @@ struct TeamDetailView: View { } label: { VStack(alignment: .leading, spacing: 0) { HStack { - Text("inscrit en ligne") + if player.registeredOnline { + Text("inscrit en ligne") + } Spacer() Text(player.localizedSourceLabel()) }