Skip to content

Commit

Permalink
[fix] tournament info 조회시 1등 상품에 대한 정보 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hysong4u committed Feb 23, 2024
1 parent c46e510 commit c254642
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@

@Builder
public record TournamentInfoDto(

String firstplaceGiftName,
String firstplaceGiftImageUrl,
int firstplaceGiftCost,
LocalDateTime remainingTime,
int totalParticipantsCount,
int participantsCount

) {
public static TournamentInfoDto of(LocalDateTime remainingTime,
int TotalParticipantsCount,
int ParticipantsCount) {
public static TournamentInfoDto of( String firstplaceGiftName,
String firstplaceGiftImageUrl,
int firstplaceGiftCost,
LocalDateTime remainingTime,
int totalParticipantsCount,
int participantsCount) {
return TournamentInfoDto.builder()
.firstplaceGiftName(firstplaceGiftName)
.firstplaceGiftImageUrl(firstplaceGiftImageUrl)
.firstplaceGiftCost(firstplaceGiftCost)
.remainingTime(remainingTime)
.totalParticipantsCount(TotalParticipantsCount)
.participantsCount(ParticipantsCount)
.totalParticipantsCount(totalParticipantsCount)
.participantsCount(participantsCount)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ 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();
Expand All @@ -212,10 +215,11 @@ public TournamentInfoDto getTournamentInfo(Long memberId, Long roomId) {
LocalDateTime tournamentEndTime = getTournamentEndDate(tournamentStartDate, tournamentDuration);
LocalDateTime remainingTime =getTournamentRemainingTime(tournamentEndTime);

return new TournamentInfoDto(remainingTime, totalParticipantsCount, participatingMembersCount);
return new TournamentInfoDto(
firstPlaceGift.getName(), firstPlaceGift.getImageUrl(), firstPlaceGift.getCost(),
remainingTime, totalParticipantsCount, participatingMembersCount);
}


private LocalDateTime getTournamentEndDate(LocalDateTime tournamentStartDate, TournamentDuration tournamentDuration) {
LocalDateTime tournamentEndTime = tournamentStartDate.plusHours(tournamentDuration.getHours());
return tournamentEndTime;
Expand Down

0 comments on commit c254642

Please sign in to comment.