Skip to content

Commit

Permalink
feat: Implement ShortGame Result Inquiry Api
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyeoon00 committed Jul 13, 2023
1 parent d586f20 commit a4f49e9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum ErrorType {
"요청 시 토큰이 누락되어 토큰 값이 없는 경우입니다."),
ALREADY_GAME_CREATED(HttpStatus.BAD_REQUEST, "UE1003",
"이미 생성된 승부가 있습니다."),
ALREADY_GAME_DONE(HttpStatus.BAD_REQUEST, "UE1005", "이미 종료된 라운드입니다."),

/**
* 401 Unauthorized
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/com/universe/uni/service/GameService.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public CreateShortGameResponseDto createShortGame(CreateShortGameRequestDto crea
User user = getUser();
Couple couple = user.getCouple();

verifyOngoingGame(couple);
verifyIsThereOngoingGame(couple);

//한판승부 생성
ShortGame shortGame = ShortGame.builder()
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit a4f49e9

Please sign in to comment.