Update counter
All checks were successful
Gitea/swiss-backend/pipeline/head This commit looks good

This commit is contained in:
Michel ten Voorde
2025-11-06 16:39:00 +01:00
parent d5df8f5d32
commit 1a1a0e373f
2 changed files with 162 additions and 127 deletions

View File

@@ -161,8 +161,10 @@ public class TournamentController {
}
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}/start")
public ResponseEntity<TournamentDto> startMatch(@PathVariable Long tournamentId, @PathVariable Long matchId,
@RequestParam("court") Long court, @RequestParam("counter") Long counter) {
public ResponseEntity<TournamentDto> startMatch(@PathVariable Long tournamentId,
@PathVariable Long matchId,
@RequestParam("court") Long court,
@RequestParam("counter") Long counter) {
var tournament = tournamentService.findTournamentById(tournamentId);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.startMatch(tournament, matchId, court, counter)));
@@ -176,14 +178,18 @@ public class TournamentController {
}
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}")
public ResponseEntity<TournamentDto> saveResult(@PathVariable Long tournamentId, @PathVariable Long matchId, @RequestBody ResultDto resultDto) {
public ResponseEntity<TournamentDto> saveResult(@PathVariable Long tournamentId,
@PathVariable Long matchId,
@RequestBody ResultDto resultDto) {
var tournament = tournamentService.findTournamentById(tournamentId);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.saveResult(tournament, matchId, resultDto)));
}
@PatchMapping("/tournaments/{tournamentId}/players/{playerId}/paid/{paid}")
public ResponseEntity<Void> updatePaid(@PathVariable Long tournamentId, @PathVariable Long playerId, @PathVariable Boolean paid) {
public ResponseEntity<Void> updatePaid(@PathVariable Long tournamentId,
@PathVariable Long playerId,
@PathVariable Boolean paid) {
var tournament = tournamentService.findTournamentById(tournamentId);
tournamentPlayService.updatePaid(tournament, playerId, paid);
@@ -192,7 +198,9 @@ public class TournamentController {
}
@PatchMapping("/tournaments/{tournamentId}/players/{playerId}/present/{present}")
public ResponseEntity<Void> updatePresent(@PathVariable Long tournamentId, @PathVariable Long playerId, @PathVariable Boolean present) {
public ResponseEntity<Void> updatePresent(@PathVariable Long tournamentId,
@PathVariable Long playerId,
@PathVariable Boolean present) {
var tournament = tournamentService.findTournamentById(tournamentId);
tournamentPlayService.updatePresent(tournament, playerId, present);
@@ -201,9 +209,21 @@ public class TournamentController {
}
@PostMapping("/tournaments/{tournamentId}/players/{playerId}/substitutions")
public ResponseEntity<TournamentDto> substitutePlayer(@PathVariable Long tournamentId, @PathVariable Long playerId, @RequestBody TournamentPlayerSubstitutionDto[] substitutions) {
public ResponseEntity<TournamentDto> substitutePlayer(@PathVariable Long tournamentId,
@PathVariable Long playerId,
@RequestBody TournamentPlayerSubstitutionDto[] substitutions) {
var tournament = tournamentService.findTournamentById(tournamentId);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.playerSubstitutions(tournament, playerId, substitutions)));
}
@PatchMapping("/tournaments/{tournamentId}/matches/{matchId}/update")
public ResponseEntity<TournamentDto> updateCounter(@PathVariable Long tournamentId,
@PathVariable Long matchId,
@RequestParam("counter") Long counter) {
var tournament = tournamentService.findTournamentById(tournamentId);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.updateCounter(tournament, matchId, counter)));
}
}

View File

@@ -220,6 +220,21 @@ public class TournamentPlayService {
return null;
}
public Tournament updateCounter(Tournament tournament, Long matchId, Long counter) {
var match = getMatch(tournament, matchId);
var currentlyCountingPlayer = getTournamentPlayer(tournament, match.getCounter().getId());
currentlyCountingPlayer.setCounting(false);
var newCountingPlayer = getTournamentPlayer(tournament, counter);
newCountingPlayer.setCounting(true);
match.setCounter(newCountingPlayer.getPlayer());
tournamentRepository.save(tournament);
return tournament;
}
private static class ConflictInDrawException extends RuntimeException {}