Skip to content

Commit

Permalink
[fix] tournament-info API 1등 상품 null일 때 예외 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hysong4u committed Feb 29, 2024
1 parent 4730752 commit f5b7930
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,25 @@ private Gift updateScore(Long giftId, int score) {
public TournamentInfoDto getTournamentInfo(Long memberId, Long roomId) {
Room room = findRoomByIdOrThrow(roomId);
RoomMember roomMember = roomMemberRepository.findByRoomIdAndMemberId(roomId, memberId);
Gift firstPlaceGift = giftRepository.findById(roomMember.getFirstplaceGiftId())
.orElseThrow(() -> new EntityNotFoundException(GIFT_NOT_FOUND));

LocalDateTime tournamentStartDate = room.getTournamentStartDate();
TournamentDuration tournamentDuration = room.getTournamentDuration();

int totalParticipantsCount = room.getGifterNumber();

int participatingMembersCount = roomMemberRepository.countByRoomIdAndTournamentParticipationIsTrue(roomId);

LocalDateTime tournamentEndTime = getTournamentEndDate(tournamentStartDate, tournamentDuration);
LocalDateTime remainingTime =getTournamentRemainingTime(tournamentEndTime);


if(roomMember.getFirstplaceGiftId() == null){
return new TournamentInfoDto(
null, null, 0,
remainingTime, totalParticipantsCount, participatingMembersCount);
}

Gift firstPlaceGift = giftRepository.findById(roomMember.getFirstplaceGiftId())
.orElseThrow(() -> new EntityNotFoundException(GIFT_NOT_FOUND));
return new TournamentInfoDto(
firstPlaceGift.getName(), firstPlaceGift.getImageUrl(), firstPlaceGift.getCost(),
remainingTime, totalParticipantsCount, participatingMembersCount);
Expand Down

0 comments on commit f5b7930

Please sign in to comment.