Add match counter
This commit is contained in:
@@ -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