diff --git a/BE/baseball/src/main/java/team9/baseball/controller/ApiGameController.java b/BE/baseball/src/main/java/team9/baseball/controller/ApiGameController.java index 2d3f27533..78ef3e5a1 100644 --- a/BE/baseball/src/main/java/team9/baseball/controller/ApiGameController.java +++ b/BE/baseball/src/main/java/team9/baseball/controller/ApiGameController.java @@ -44,4 +44,9 @@ public ApiResult pitch(PitchResult pitchResult) { gameService.applyPitchResult(1l, pitchResult); return ApiResult.succeed("OK"); } + + @GetMapping("/history") + public ApiResult getCurrentGameHistory() { + return ApiResult.succeed(gameService.getCurrentGameHistory(1l)); + } } diff --git a/BE/baseball/src/main/java/team9/baseball/service/GameService.java b/BE/baseball/src/main/java/team9/baseball/service/GameService.java index c8215169b..8ba2b306a 100644 --- a/BE/baseball/src/main/java/team9/baseball/service/GameService.java +++ b/BE/baseball/src/main/java/team9/baseball/service/GameService.java @@ -3,6 +3,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import team9.baseball.DTO.response.GameDescriptionDTO; +import team9.baseball.DTO.response.GameHistoryDTO; import team9.baseball.DTO.response.GameStatusDTO; import team9.baseball.domain.aggregate.game.Game; import team9.baseball.domain.aggregate.team.Team; @@ -69,6 +70,18 @@ public GameStatusDTO getCurrentGameStatus(long userId) { return GameStatusDTO.of(game, awayTeam, homeTeam, user.getCurrentGameVenue()); } + public GameHistoryDTO getCurrentGameHistory(long userId) { + User user = getUser(userId); + if (user.getCurrentGameId() == null) { + throw new RuntimeException(userId + "사용자는 게임중이 아닙니다."); + } + Game game = getGame(user.getCurrentGameId()); + Team awayTeam = getTeam(game.getAwayTeamId()); + Team homeTeam = getTeam(game.getHomeTeamId()); + + return GameHistoryDTO.of(game, awayTeam, homeTeam); + } + public void createNewGame(long userId, int awayTeamId, int homeTeamId) { User user = getUser(userId); Team awayTeam = getTeam(awayTeamId);