diff --git a/src/main/java/org/sopt/sweet/domain/gift/dto/response/TournamentInfoDto.java b/src/main/java/org/sopt/sweet/domain/gift/dto/response/TournamentInfoDto.java index 0d8b4e3..42cc190 100644 --- a/src/main/java/org/sopt/sweet/domain/gift/dto/response/TournamentInfoDto.java +++ b/src/main/java/org/sopt/sweet/domain/gift/dto/response/TournamentInfoDto.java @@ -7,22 +7,18 @@ @Builder public record TournamentInfoDto( - LocalDateTime tournamentStartDate, - TournamentDuration tournamentDuration, - - int TotalParticipantsCount, - int ParticipantsCount + LocalDateTime remainingTime, + int totalParticipantsCount, + int participantsCount ) { - public static TournamentInfoDto of(LocalDateTime tournamentStartDate, - TournamentDuration tournamentDuration, + public static TournamentInfoDto of(LocalDateTime remainingTime, int TotalParticipantsCount, int ParticipantsCount) { return TournamentInfoDto.builder() - .tournamentStartDate(tournamentStartDate) - .tournamentDuration(tournamentDuration) - .TotalParticipantsCount(TotalParticipantsCount) - .ParticipantsCount(ParticipantsCount) + .remainingTime(remainingTime) + .totalParticipantsCount(TotalParticipantsCount) + .participantsCount(ParticipantsCount) .build(); } diff --git a/src/main/java/org/sopt/sweet/domain/gift/service/GiftService.java b/src/main/java/org/sopt/sweet/domain/gift/service/GiftService.java index 5609cef..8b79dff 100644 --- a/src/main/java/org/sopt/sweet/domain/gift/service/GiftService.java +++ b/src/main/java/org/sopt/sweet/domain/gift/service/GiftService.java @@ -2,7 +2,6 @@ import lombok.RequiredArgsConstructor; import org.sopt.sweet.domain.gift.dto.request.CreateGiftRequestDto; -import org.sopt.sweet.domain.gift.dto.request.MyGiftsRequestDto; import org.sopt.sweet.domain.gift.dto.request.TournamentScoreRequestDto; import org.sopt.sweet.domain.gift.dto.response.*; import org.sopt.sweet.domain.gift.entity.Gift; @@ -20,6 +19,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.Duration; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Comparator; @@ -27,7 +27,6 @@ import java.util.Optional; import java.util.stream.Collectors; -import static org.codehaus.groovy.runtime.DefaultGroovyMethods.collect; import static org.sopt.sweet.global.error.ErrorCode.*; @RequiredArgsConstructor @@ -186,10 +185,25 @@ public TournamentInfoDto getTournamentInfo(Long memberId, Long roomId) { int participatingMembersCount = roomMemberRepository.countByRoomIdAndTournamentParticipationIsTrue(roomId); - return new TournamentInfoDto(tournamentStartDate, tournamentDuration, totalParticipantsCount, participatingMembersCount); + LocalDateTime tournamentEndTime = getTournamentEndDate(tournamentStartDate, tournamentDuration); + LocalDateTime remainingTime =getTournamentRemainingTime(tournamentEndTime); + + return new TournamentInfoDto(remainingTime, totalParticipantsCount, participatingMembersCount); } + private LocalDateTime getTournamentEndDate(LocalDateTime tournamentStartDate, TournamentDuration tournamentDuration) { + LocalDateTime tournamentEndTime = tournamentStartDate.plusHours(tournamentDuration.getHours()); + return tournamentEndTime; + } + + + private LocalDateTime getTournamentRemainingTime(LocalDateTime tournamentEndTime) { + return tournamentEndTime + .minusHours(LocalDateTime.now().getHour()) + .minusMinutes(LocalDateTime.now().getMinute()) + .minusSeconds(LocalDateTime.now().getSecond()); + } public void updateTournamentParticipation(Long memberId, Long roomId) { RoomMember roomMember = roomMemberRepository.findByRoomIdAndMemberId(roomId, memberId);