Add match counter
This commit is contained in:
@@ -156,11 +156,12 @@ public class TournamentController {
|
||||
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.newRound(tournament, groupId)));
|
||||
}
|
||||
|
||||
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}/start/{court}")
|
||||
public ResponseEntity<TournamentDto> startMatch(@PathVariable Long tournamentId, @PathVariable Long matchId, @PathVariable Long court) {
|
||||
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}/start")
|
||||
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)));
|
||||
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.startMatch(tournament, matchId, court, counter)));
|
||||
}
|
||||
|
||||
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}/stop")
|
||||
|
||||
@@ -39,6 +39,9 @@ public class Match extends AbstractEntity {
|
||||
|
||||
private Long court;
|
||||
|
||||
@ManyToOne
|
||||
private Player counter;
|
||||
|
||||
@OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
||||
private List<Game> games;// = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -28,4 +28,8 @@ public class TournamentPlayer extends AbstractEntity {
|
||||
private boolean paid;
|
||||
|
||||
private boolean present;
|
||||
|
||||
private boolean counting;
|
||||
|
||||
private Long counts;
|
||||
}
|
||||
|
||||
@@ -29,4 +29,6 @@ public class MatchDto extends AbstractDto {
|
||||
private LocalDateTime endTime;
|
||||
|
||||
private Long court;
|
||||
|
||||
private PlayerDto counter;
|
||||
}
|
||||
|
||||
@@ -20,4 +20,8 @@ public class TournamentPlayerDto extends AbstractDto {
|
||||
|
||||
private Boolean present;
|
||||
|
||||
private Boolean counting;
|
||||
|
||||
private Long counts;
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ public class MatchMapper implements DtoMapper<Match, MatchDto> {
|
||||
|
||||
private final GameMapper gameMapper;
|
||||
|
||||
private final PlayerMapper playerMapper;
|
||||
|
||||
@Override
|
||||
public MatchDto toDto(Match match) {
|
||||
var matchDto = new MatchDto();
|
||||
@@ -25,6 +27,9 @@ public class MatchMapper implements DtoMapper<Match, MatchDto> {
|
||||
matchDto.setStartTime(match.getStartTime());
|
||||
matchDto.setEndTime(match.getEndTime());
|
||||
matchDto.setCourt(match.getCourt());
|
||||
if (match.getCounter() != null) {
|
||||
matchDto.setCounter(playerMapper.toDto(match.getCounter()));
|
||||
}
|
||||
|
||||
if (match.getGames() != null) {
|
||||
matchDto.setGames(
|
||||
|
||||
@@ -13,8 +13,6 @@ import java.util.ArrayList;
|
||||
@RequiredArgsConstructor
|
||||
public class TournamentPlayerMapper implements DtoMapper<TournamentPlayer, TournamentPlayerDto> {
|
||||
|
||||
private final PlayerMapper playerMapper;
|
||||
|
||||
@Override
|
||||
public TournamentPlayerDto toDto(TournamentPlayer tournamentPlayer) {
|
||||
var tournamentPlayerDto = new TournamentPlayerDto();
|
||||
@@ -23,6 +21,8 @@ public class TournamentPlayerMapper implements DtoMapper<TournamentPlayer, Tourn
|
||||
tournamentPlayerDto.setEvents(new ArrayList<>(tournamentPlayer.getEvents()));
|
||||
tournamentPlayerDto.setPaid(tournamentPlayer.isPaid());
|
||||
tournamentPlayerDto.setPresent(tournamentPlayer.isPresent());
|
||||
tournamentPlayerDto.setCounting(tournamentPlayer.isCounting());
|
||||
tournamentPlayerDto.setCounts(tournamentPlayer.getCounts());
|
||||
|
||||
return tournamentPlayerDto;
|
||||
}
|
||||
|
||||
@@ -166,26 +166,39 @@ public class TournamentPlayService {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean playerHasSkippedRoundBefore(Player player, Tournament tournament) {
|
||||
var hasSkippedRound = false;
|
||||
|
||||
return hasSkippedRound;
|
||||
}
|
||||
|
||||
public Tournament startMatch(Tournament tournament, Long matchId, Long court) {
|
||||
public Tournament startMatch(Tournament tournament, Long matchId, Long court, Long counter) {
|
||||
var match = getMatch(tournament, matchId);
|
||||
match.setStatus(Status.IN_PROGRESS);
|
||||
match.setStartTime(LocalDateTime.now());
|
||||
match.setCourt(court);
|
||||
|
||||
var countingPlayer = getPlayer(tournament, counter);
|
||||
countingPlayer.setCounting(true);
|
||||
match.setCounter(countingPlayer.getPlayer());
|
||||
|
||||
tournamentRepository.save(tournament);
|
||||
return tournament;
|
||||
}
|
||||
|
||||
private TournamentPlayer getPlayer(Tournament tournament, Long playerId) {
|
||||
for (var tournamentPlayer : tournament.getTournamentPlayers()) {
|
||||
if (playerId.equals(tournamentPlayer.getPlayer().getId())) {
|
||||
return tournamentPlayer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Tournament stopMatch(Tournament tournament, Long matchId) {
|
||||
var match = getMatch(tournament, matchId);
|
||||
match.setStatus(Status.NOT_STARTED);
|
||||
match.setStartTime(null);
|
||||
match.setCourt(null);
|
||||
|
||||
var countingPlayer = getPlayer(tournament, match.getCounter().getId());
|
||||
countingPlayer.setCounting(false);
|
||||
match.setCounter(null);
|
||||
|
||||
tournamentRepository.save(tournament);
|
||||
return tournament;
|
||||
}
|
||||
@@ -200,6 +213,10 @@ public class TournamentPlayService {
|
||||
match.getGames().clear();
|
||||
match.getGames().addAll(resultToGames(result, match));
|
||||
|
||||
var countingPlayer = getPlayer(tournament, match.getCounter().getId());
|
||||
countingPlayer.setCounting(false);
|
||||
match.setCounter(null);
|
||||
|
||||
tournamentRepository.save(tournament);
|
||||
return tournament;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user