Skip to content

Commit

Permalink
[fix] 토너먼트 종료시 정보 조회 API response 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
hysong4u committed Jan 19, 2024
1 parent ffe92cb commit 0c60afd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
20 changes: 17 additions & 3 deletions src/main/java/org/sopt/sweet/domain/gift/service/GiftService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,14 +19,14 @@
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;
import java.util.List;
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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0c60afd

Please sign in to comment.