Skip to content

Commit

Permalink
🔨 refactor: 매칭 첫 경기의 시작시간 계산 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimhan-nah committed Dec 18, 2023
1 parent acc9dde commit 787b080
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void matchGames(Tournament tournament, TournamentRound round) {
List<TournamentGame> allTournamentGames = tournamentGameRepository.findAllByTournamentId(tournament.getId());
List<TournamentGame> tournamentGames = findSameRoundGames(allTournamentGames, round.getRoundNumber());
List<TournamentGame> previousRoundTournamentGames = findSameRoundGames(allTournamentGames, TournamentRound.getPreviousRoundNumber(round));
LocalDateTime startTime = findLastGameEndTime(tournament, round).plusMinutes(gameInterval);
LocalDateTime startTime = calculateStartTime(tournament, round, gameInterval);

for (int i = 0; i < tournamentGames.size(); ++i) {
startTime = startTime.plusMinutes((long) gameInterval * i);
Expand Down Expand Up @@ -139,17 +139,18 @@ public void updateMatchedGameUser(Game modifiedGame, Game nextMatchedGame) {
/**
* @param tournament 토너먼트
* @param round 토너먼트 라운드
* @return 마지막 경기 종료 시간
* @param gameInterval 경기 간격
* @return 마지막 경기 종료 시간 + interval
* <p>8강의 경우 토너먼트 시작 시간</p>
* <p>4강, 결승일 경우 이전 라운드의 마지막 경기 종료 시간</p>
* <p>4강, 결승일 경우 이전 라운드의 마지막 경기 종료 시간 + 15분</p>
*/
private LocalDateTime findLastGameEndTime(Tournament tournament, TournamentRound round) {
private LocalDateTime calculateStartTime(Tournament tournament, TournamentRound round, int gameInterval) {
if (TournamentRound.QUARTER_FINAL_1.getRoundNumber() == round.getRoundNumber()) {
return tournament.getStartTime();
}
List<TournamentGame> previousRoundTournamentGames = findSameRoundGames(tournament.getTournamentGames(), TournamentRound.getPreviousRoundNumber(round));
TournamentGame lastGame = previousRoundTournamentGames.get(previousRoundTournamentGames.size() - 1);
return lastGame.getGame().getEndTime();
return lastGame.getGame().getEndTime().plusMinutes(gameInterval);
}

private User findMatchUser(List<TournamentGame> previousTournamentGames, int index, Tournament tournament) {
Expand Down

0 comments on commit 787b080

Please sign in to comment.