sync2
Laurent 10 months ago
parent 7a0d2a8da7
commit bdea94f472
  1. 118
      PadelClub/Data/DataStore.swift

@ -231,65 +231,65 @@ class DataStore: ObservableObject {
} }
func copyToLocalServer(tournament: Tournament) { // func copyToLocalServer(tournament: Tournament) {
//
Task { // Task {
do { // do {
//
if let url = PListReader.readString(plist: "local", key: "local_server"), // if let url = PListReader.readString(plist: "local", key: "local_server"),
let login = PListReader.readString(plist: "local", key: "username"), // let login = PListReader.readString(plist: "local", key: "username"),
let pass = PListReader.readString(plist: "local", key: "password") { // let pass = PListReader.readString(plist: "local", key: "password") {
let service = Services(url: url) // let service = Services(url: url)
let _: CustomUser = try await service.login(username: login, password: pass) // let _: CustomUser = try await service.login(username: login, password: pass)
//
tournament.event = nil // tournament.event = nil
_ = try await service.post(tournament) // _ = try await service.post(tournament)
//
for groupStage in tournament.groupStages() { // for groupStage in tournament.groupStages() {
_ = try await service.post(groupStage) // _ = try await service.post(groupStage)
} // }
for round in tournament.rounds() { // for round in tournament.rounds() {
try await self._insertRoundAndChildren(round: round, service: service) // try await self._insertRoundAndChildren(round: round, service: service)
} // }
for teamRegistration in tournament.unsortedTeams() { // for teamRegistration in tournament.unsortedTeams() {
_ = try await service.post(teamRegistration) // _ = try await service.post(teamRegistration)
for playerRegistration in teamRegistration.unsortedPlayers() { // for playerRegistration in teamRegistration.unsortedPlayers() {
_ = try await service.post(playerRegistration) // _ = try await service.post(playerRegistration)
} // }
} // }
for groupStage in tournament.groupStages() { // for groupStage in tournament.groupStages() {
for match in groupStage._matches() { // for match in groupStage._matches() {
try await self._insertMatch(match: match, service: service) // try await self._insertMatch(match: match, service: service)
} // }
} // }
for round in tournament.allRounds() { // for round in tournament.allRounds() {
for match in round._matches() { // for match in round._matches() {
try await self._insertMatch(match: match, service: service) // try await self._insertMatch(match: match, service: service)
} // }
} // }
//
} // }
} catch { // } catch {
Logger.error(error) // Logger.error(error)
} // }
} // }
//
} // }
//
fileprivate func _insertRoundAndChildren(round: Round, service: Services) async throws { // fileprivate func _insertRoundAndChildren(round: Round, service: Services) async throws {
_ = try await service.post(round) // _ = try await service.post(round)
for loserRound in round.loserRounds() { // for loserRound in round.loserRounds() {
try await self._insertRoundAndChildren(round: loserRound, service: service) // try await self._insertRoundAndChildren(round: loserRound, service: service)
} // }
} // }
//
fileprivate func _insertMatch(match: Match, service: Services) async throws { // fileprivate func _insertMatch(match: Match, service: Services) async throws {
_ = try await service.post(match) // _ = try await service.post(match)
for teamScore in match.teamScores { // for teamScore in match.teamScores {
_ = try await service.post(teamScore) // _ = try await service.post(teamScore)
} // }
//
} // }
// MARK: - Convenience // MARK: - Convenience

Loading…
Cancel
Save