From a4f49e9ada27ff8e17123d5776e4231fcffc7765 Mon Sep 17 00:00:00 2001 From: jiyeon Date: Fri, 14 Jul 2023 01:00:42 +0900 Subject: [PATCH] feat: Implement ShortGame Result Inquiry Api --- .../uni/controller/ShortGameController.java | 5 +++++ .../universe/uni/exception/dto/ErrorType.java | 1 + .../com/universe/uni/service/GameService.java | 21 +++++++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/universe/uni/controller/ShortGameController.java b/src/main/java/com/universe/uni/controller/ShortGameController.java index 11246b0..56b974f 100644 --- a/src/main/java/com/universe/uni/controller/ShortGameController.java +++ b/src/main/java/com/universe/uni/controller/ShortGameController.java @@ -2,6 +2,7 @@ import javax.validation.Valid; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -37,4 +38,8 @@ public GameReportResponseDto enterGameResult( return gameService.updateGameScore(roundGameId, enterGameResultDto.getResult()); } + @GetMapping("/{roundGameId}") + public GameReportResponseDto showGameReport(@PathVariable final Long roundGameId) { + return gameService.getGameReportIfGameIsOngoing(roundGameId); + } } diff --git a/src/main/java/com/universe/uni/exception/dto/ErrorType.java b/src/main/java/com/universe/uni/exception/dto/ErrorType.java index 7106de6..fe97a78 100644 --- a/src/main/java/com/universe/uni/exception/dto/ErrorType.java +++ b/src/main/java/com/universe/uni/exception/dto/ErrorType.java @@ -19,6 +19,7 @@ public enum ErrorType { "요청 시 토큰이 누락되어 토큰 값이 없는 경우입니다."), ALREADY_GAME_CREATED(HttpStatus.BAD_REQUEST, "UE1003", "이미 생성된 승부가 있습니다."), + ALREADY_GAME_DONE(HttpStatus.BAD_REQUEST, "UE1005", "이미 종료된 라운드입니다."), /** * 401 Unauthorized diff --git a/src/main/java/com/universe/uni/service/GameService.java b/src/main/java/com/universe/uni/service/GameService.java index d29c39c..4456af4 100644 --- a/src/main/java/com/universe/uni/service/GameService.java +++ b/src/main/java/com/universe/uni/service/GameService.java @@ -53,7 +53,7 @@ public CreateShortGameResponseDto createShortGame(CreateShortGameRequestDto crea User user = getUser(); Couple couple = user.getCouple(); - verifyOngoingGame(couple); + verifyIsThereOngoingGame(couple); //한판승부 생성 ShortGame shortGame = ShortGame.builder() @@ -110,7 +110,7 @@ private User getUser() { return byId.get(); } - private void verifyOngoingGame(Couple couple) { + private void verifyIsThereOngoingGame(Couple couple) { if(gameRepository.existsByCoupleAndEnable(couple, true)) { throw new BadRequestException(ALREADY_GAME_CREATED); } @@ -233,4 +233,21 @@ private RoundGame getRoundGameById(Long roundGameId) { return roundGameRepository.findById(roundGameId) .orElseThrow(() -> new NotFoundException(NOT_FOUND_ROUND_MISSION)); } + + @Transactional(readOnly = true) + public GameReportResponseDto getGameReportIfGameIsOngoing(Long roundGameId) { + User user = getUser(); + RoundGame roundGame = getRoundGameById(roundGameId); + + verifyIsOngoingGame(roundGame); + RoundMission myRoundMission = getRoundMissionByRoundGameAndUser(roundGame, user); + + return GameReportResponseDto.of(myRoundMission); + } + + private void verifyIsOngoingGame(RoundGame roundGame) { + if(!roundGame.getEnable()) { + throw new BadRequestException(ALREADY_GAME_DONE); + } + } }