This commit is contained in:
@@ -161,8 +161,10 @@ public class TournamentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}/start")
|
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}/start")
|
||||||
public ResponseEntity<TournamentDto> startMatch(@PathVariable Long tournamentId, @PathVariable Long matchId,
|
public ResponseEntity<TournamentDto> startMatch(@PathVariable Long tournamentId,
|
||||||
@RequestParam("court") Long court, @RequestParam("counter") Long counter) {
|
@PathVariable Long matchId,
|
||||||
|
@RequestParam("court") Long court,
|
||||||
|
@RequestParam("counter") Long counter) {
|
||||||
var tournament = tournamentService.findTournamentById(tournamentId);
|
var tournament = tournamentService.findTournamentById(tournamentId);
|
||||||
|
|
||||||
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.startMatch(tournament, matchId, court, counter)));
|
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.startMatch(tournament, matchId, court, counter)));
|
||||||
@@ -176,14 +178,18 @@ public class TournamentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}")
|
@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);
|
var tournament = tournamentService.findTournamentById(tournamentId);
|
||||||
|
|
||||||
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.saveResult(tournament, matchId, resultDto)));
|
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.saveResult(tournament, matchId, resultDto)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PatchMapping("/tournaments/{tournamentId}/players/{playerId}/paid/{paid}")
|
@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);
|
var tournament = tournamentService.findTournamentById(tournamentId);
|
||||||
|
|
||||||
tournamentPlayService.updatePaid(tournament, playerId, paid);
|
tournamentPlayService.updatePaid(tournament, playerId, paid);
|
||||||
@@ -192,7 +198,9 @@ public class TournamentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PatchMapping("/tournaments/{tournamentId}/players/{playerId}/present/{present}")
|
@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);
|
var tournament = tournamentService.findTournamentById(tournamentId);
|
||||||
|
|
||||||
tournamentPlayService.updatePresent(tournament, playerId, present);
|
tournamentPlayService.updatePresent(tournament, playerId, present);
|
||||||
@@ -201,9 +209,21 @@ public class TournamentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/tournaments/{tournamentId}/players/{playerId}/substitutions")
|
@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);
|
var tournament = tournamentService.findTournamentById(tournamentId);
|
||||||
|
|
||||||
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.playerSubstitutions(tournament, playerId, substitutions)));
|
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)));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -220,6 +220,21 @@ public class TournamentPlayService {
|
|||||||
return null;
|
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 {}
|
private static class ConflictInDrawException extends RuntimeException {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user