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