Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [Feature] 토너먼트 게임 매칭 로직 추가 #404

Merged
merged 47 commits into from
Dec 18, 2023
Merged
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
12211ae
:sparkles: feat: TournamentRound roundNumber 및 메서드 추가
Kimhan-nah Dec 13, 2023
f4b4b76
:sparkles: feat: Game의 getWinnerTeam 함수 추가
Kimhan-nah Dec 13, 2023
b8c2636
:sparkles: feat: 같은 round의 토너먼트 게임 반환 함수 추가
Kimhan-nah Dec 13, 2023
3290182
:sparkles: feat: 토너먼트 매칭 로직 추가
Kimhan-nah Dec 13, 2023
a305b87
:bug: fix: GameController 테스트에 tournament game 데이터 생성 추가
Kimhan-nah Dec 13, 2023
238498a
:bug: fix: 같은 round의 모든 game 반환하도록 filter 조건 수정
Kimhan-nah Dec 13, 2023
6ecfdd7
:test_tube: test: MathTournamentTest 추가
Kimhan-nah Dec 13, 2023
90aad10
:sparkles: feat: 토너먼트 게임 결과 수정에 매칭 로직 추가
Kimhan-nah Dec 13, 2023
a3b9dce
:hammer: refactor: return type Optional로 수정
Kimhan-nah Dec 15, 2023
e68a941
:hammer: refactor: 결승전 roundNum 2로 수정
Kimhan-nah Dec 15, 2023
c463656
:hammer: refactor: TeamUser에 updateUser 추가
Kimhan-nah Dec 15, 2023
044bea5
:sparkles: feat: TournamentMatch Enum class 생성
Kimhan-nah Dec 15, 2023
266ac3a
:sparkles: feat: 토너먼트 다음 경기의 플레이어 수정 함수 추가
Kimhan-nah Dec 15, 2023
9ddff39
:hammer: refactor: 토너먼트 매칭 함수 호출 수정
Kimhan-nah Dec 15, 2023
d5563f0
:test_tube: test: MatchTestUtils에 중복된 함수 리팩토링
Kimhan-nah Dec 15, 2023
b281c95
:hammer: refactor: MatchTestUtils util 폴더로 이동
Kimhan-nah Dec 16, 2023
cdc7782
:hammer: refactor: test util 및 토너먼트 결과 수정 테스트 코드 수정
Kimhan-nah Dec 16, 2023
1621c1d
:bug: fix: 중복된 touranment game repository 삭제
Kimhan-nah Dec 16, 2023
d03d55e
:bug: fix: match test util 파일 이동으로 인한 import 수정
Kimhan-nah Dec 16, 2023
f1e62fc
:test_tube: test: 매칭되어 있는 다음 경기의 팀 수정 테스트 추가
Kimhan-nah Dec 16, 2023
7f97e22
:hammer: refactor: TournamentMatchStatus enum 클래스명 수정
Kimhan-nah Dec 16, 2023
0e4152e
:hammer: refactor: tournament match status 수정
Kimhan-nah Dec 16, 2023
2d08c0b
:sparkles: feat: 토너먼트 슬롯 블락 시간 interval 고려하여 블락
Kimhan-nah Dec 16, 2023
f7b169d
:bug: fix: 게임 매칭할 때 시작 시간 라운드별 다르게 수정
Kimhan-nah Dec 16, 2023
65ca622
:hammer: refactor: exception errorCode 일치하도록 수정
Kimhan-nah Dec 16, 2023
682a80d
:sparkles: feat: TeamNotFoundException 추가
Kimhan-nah Dec 16, 2023
7c372af
:hammer: refactor: custom exception으로 수정
Kimhan-nah Dec 16, 2023
ed9c70b
:bug: fix: updateMatchedGameUser 테스트 fail 수정
Kimhan-nah Dec 16, 2023
ad6ad63
:bug: fix: 라운드별 match game의 team user가 비정상적인 문제 수정
Kimhan-nah Dec 16, 2023
744bacb
:sparkles: feat: 우승팀 not found exception 추가
Kimhan-nah Dec 17, 2023
420915b
:bug: fix: user id와 team id를 비교하는 잘못된 로직 수정
Kimhan-nah Dec 17, 2023
23418cd
:hammer: refactor: updateMatchedGameUser 파라미터명 수정
Kimhan-nah Dec 17, 2023
d92b4a2
:test_tube: test: 우승팀 존재하지 않는 실패 케이스 추가
Kimhan-nah Dec 17, 2023
eec69d7
:test_tube: test: 이미 매칭된 게임 존재하는 실패 케이스 추가
Kimhan-nah Dec 17, 2023
dcb5147
:test_tube: test: checkTournamentGame return 값 테스트 추가
Kimhan-nah Dec 17, 2023
4a3643a
:green_heart: chore: QA를 위한 스케줄러 주기 임시 변경
Kimhan-nah Dec 17, 2023
103e7ae
:hammer: refactor: MatchTournamentService에 Transactional 추가
Kimhan-nah Dec 17, 2023
dada981
:bug: fix: 연관관계 메서드 수정으로 인한 add 삭제
Kimhan-nah Dec 17, 2023
10abb2a
:hammer: refactor: 불필요한 enum의 get 함수 삭제
Kimhan-nah Dec 17, 2023
f88fd69
:hammer: refactor: updateUser에 null check 추가
Kimhan-nah Dec 17, 2023
2cf7bae
:bug: fix: 사용중인 enum 메서드 되돌리기
Kimhan-nah Dec 17, 2023
c88c77b
:hammer: refactor: getWinningTeam() game에서 service 이동
Kimhan-nah Dec 17, 2023
6026e32
:bug: fix: 메서드 이동에 따른 에러 수정
Kimhan-nah Dec 17, 2023
f7221b1
:hammer: refactor: 불필요한 enum 메서드 삭제
Kimhan-nah Dec 17, 2023
09b9ace
:hammer: refactor: exception throw 추가
Kimhan-nah Dec 17, 2023
8edd7cb
:hammer: refactor: 매칭 첫 경기의 시작시간 계산 수정
Kimhan-nah Dec 18, 2023
54a34b6
:bug: fix: 스케줄러 cron 수정
Kimhan-nah Dec 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
🔨 refactor: custom exception으로 수정
Kimhan-nah committed Dec 18, 2023
commit 7c372af8a5791dfedccb11c8f92142adc1e8ed5c
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@
import com.gg.server.domain.tournament.data.Tournament;
import com.gg.server.domain.tournament.data.TournamentGame;
import com.gg.server.domain.tournament.data.TournamentGameRepository;
import com.gg.server.domain.tournament.exception.TournamentGameNotFoundException;
import com.gg.server.global.exception.ErrorCode;
import com.gg.server.global.exception.custom.InvalidParameterException;
import com.gg.server.global.utils.ExpLevelCalculator;
@@ -109,7 +110,7 @@ public void createTournamentGameResult(TournamentResultReqDto scoreDto, Long use
updateTournamentGameScore(game, scoreDto, userId);
if (TournamentMatchStatus.POSSIBLE.equals(matchTournamentService.checkTournamentGame(game))) {
TournamentGame tournamentGame = tournamentGameRepository.findByGameId(game.getId())
.orElseThrow(GameNotExistException::new);
.orElseThrow(TournamentGameNotFoundException::new);
Tournament tournament = tournamentGame.getTournament();
matchTournamentService.matchGames(tournament, tournamentGame.getTournamentRound().getNextRound());
}
Original file line number Diff line number Diff line change
@@ -4,13 +4,15 @@
import com.gg.server.domain.game.data.GameRepository;
import com.gg.server.domain.game.type.Mode;
import com.gg.server.domain.game.type.StatusType;
import com.gg.server.domain.match.exception.EnrolledSlotException;
import com.gg.server.domain.match.type.TournamentMatchStatus;
import com.gg.server.domain.season.data.Season;
import com.gg.server.domain.season.service.SeasonFindService;
import com.gg.server.domain.slotmanagement.SlotManagement;
import com.gg.server.domain.slotmanagement.data.SlotManagementRepository;
import com.gg.server.domain.team.data.Team;
import com.gg.server.domain.team.data.TeamUser;
import com.gg.server.domain.team.exception.TeamNotFoundException;
import com.gg.server.domain.tournament.data.Tournament;
import com.gg.server.domain.tournament.data.TournamentGame;
import com.gg.server.domain.tournament.data.TournamentGameRepository;
@@ -46,11 +48,11 @@ public class MatchTournamentService {
* <p> 결승전 점수 입력 후 토너먼트 END 상태로 업데이트 </p>
* @param game 토너먼트 게임
* @return TournamentMatchStatus - 매칭 가능 여부
* @throws IllegalArgumentException 토너먼트 게임이 아닐 경우
* @throws TournamentGameNotFoundException 토너먼트 게임이 존재하지 않을 경우
*/
public TournamentMatchStatus checkTournamentGame(Game game) {
TournamentGame tournamentGame = tournamentGameRepository.findByGameId(game.getId())
.orElseThrow(() -> new CustomRuntimeException("토너먼트 게임이 아닙니다.", ErrorCode.TOURNAMENT_NOT_FOUND)); // TODO : custom exception
.orElseThrow(TournamentGameNotFoundException::new);

// 토너먼트 결승전 게임일 경우, 토너먼트 상태 END로 변경
if (TournamentRound.THE_FINAL.equals(tournamentGame.getTournamentRound())) {
@@ -80,11 +82,12 @@ public TournamentMatchStatus checkTournamentGame(Game game) {
* 토너먼트 게임 매칭
* @param tournament 토너먼트
* @param round 새로 매칭할 토너먼트 라운드
* @throws NullPointerException round의 이전 라운드가 존재하지 않을 경우
* @throws EnrolledSlotException 이미 매칭된 게임이 존재할 경우
* @throws SlotNotFoundException 슬롯이 존재하지 않을 경우
*/
public void matchGames(Tournament tournament, TournamentRound round) {
if (isAlreadyExistMatchedGame(tournament, round)) {
throw new CustomRuntimeException("이미 매칭된 게임이 존재합니다.", ErrorCode.TOURNAMENT_NOT_FOUND); // TODO 수정
throw new EnrolledSlotException();
}
Season season = seasonFindService.findCurrentSeason(tournament.getStartTime());
SlotManagement slotManagement = slotManagementRepository.findCurrent(tournament.getStartTime())
@@ -113,10 +116,11 @@ public void matchGames(Tournament tournament, TournamentRound round) {
* 토너먼트 게임의 승자를 토너먼트 다음 라운드의 게임 플레이어로 업데이트
* @param game 경기 결과가 수정된 토너먼트 게임
* @param nextMatchedGame 수정된 우승자로 수정할 다음 게임
* @throws TeamNotFoundException 우승팀이 존재하지 않을 경우
*/
public void updateMatchedGameUser(Game game, Game nextMatchedGame) {
List<Long> teamIds = game.getTeams().stream().map(Team::getId).collect(Collectors.toList());
Team winningTeam = game.getWinningTeam().orElseThrow(); // TODO : throw exception
Team winningTeam = game.getWinningTeam().orElseThrow(TeamNotFoundException::new);

List<Team> nextMatchedGameTeams = nextMatchedGame.getTeams();
for (Team team : nextMatchedGameTeams) {
@@ -148,7 +152,7 @@ private User findMatchUser(List<TournamentGame> previousTournamentGames, int ind
return tournament.getTournamentUsers().get(index).getUser();
}
return previousTournamentGames.get(index).getGame().getWinningTeam()
.orElseThrow(() -> new IllegalArgumentException("이전 라운드의 승자가 존재하지 않습니다."))
.orElseThrow(TeamNotFoundException::new)
.getTeamUsers().get(0).getUser();
}

@@ -157,6 +161,7 @@ private User findMatchUser(List<TournamentGame> previousTournamentGames, int ind
* @param tournament 토너먼트
* @param round 토너먼트 라운드
* @return true - 매칭된 게임이 존재, false - 아직 매칭된 게임이 존재하지 않음
* @throws TournamentGameNotFoundException 토너먼트 게임이 존재하지 않을 경우
*/
private boolean isAlreadyExistMatchedGame(Tournament tournament, TournamentRound round) {
TournamentGame tournamentGame = tournamentGameRepository.findByTournamentIdAndTournamentRound(tournament.getId(), round)
@@ -170,10 +175,11 @@ private boolean isAlreadyExistMatchedGame(Tournament tournament, TournamentRound
* <p> 토너먼트 winner 업데이트 </p>
* @param tournament 종료할 토너먼트
* @param finalGame 토너먼트의 마지막 게임
* @throws TeamNotFoundException 우승팀이 존재하지 않을 경우
*/
private void closeTournament(Tournament tournament, Game finalGame) {
User winner = finalGame.getWinningTeam()
.orElseThrow(() -> new CustomRuntimeException("승자가 존재하지 않습니다.", ErrorCode.TOURNAMENT_NOT_FOUND))
.orElseThrow(TeamNotFoundException::new)
.getTeamUsers().get(0).getUser();
tournament.updateStatus(TournamentStatus.END);
tournament.updateWinner(winner);