Skip to content

Commit

Permalink
[#6] Implements API that response current game history
Browse files Browse the repository at this point in the history
현재 게임 기록 (스코어, 타율) 을 반환해주는 API 구현
  • Loading branch information
isaac56 committed May 7, 2021
1 parent 8aedf48 commit 858a04d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
13 changes: 13 additions & 0 deletions BE/baseball/src/main/java/team9/baseball/service/GameService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 858a04d

Please sign in to comment.