Skip to content

Commit

Permalink
[fix] 진행중, 종료 선물방 분류 기준 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
hysong4u committed Jan 19, 2024
1 parent adff6bb commit ffe92cb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public TournamentInfoDto getTournamentInfo(Long memberId, Long roomId) {

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

int totalParticipantsCount = room.getGifterNumber();

updateTournamentParticipation(memberId, roomId);
Expand All @@ -188,6 +189,8 @@ public TournamentInfoDto getTournamentInfo(Long memberId, Long roomId) {
return new TournamentInfoDto(tournamentStartDate, tournamentDuration, totalParticipantsCount, participatingMembersCount);
}



public void updateTournamentParticipation(Long memberId, Long roomId) {
RoomMember roomMember = roomMemberRepository.findByRoomIdAndMemberId(roomId, memberId);
roomMember.setTournamentParticipation(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.sopt.sweet.domain.member.dto.response.MemberTokenResponseDto;
import org.sopt.sweet.domain.member.entity.Member;
import org.sopt.sweet.domain.member.repository.MemberRepository;
import org.sopt.sweet.domain.room.constant.TournamentDuration;
import org.sopt.sweet.domain.room.entity.Room;
import org.sopt.sweet.domain.room.entity.RoomMember;
import org.sopt.sweet.domain.room.repository.RoomMemberRepository;
Expand Down Expand Up @@ -50,8 +51,11 @@ public List<ClosedRoomResponseDto> getClosedRoom(Long memberId) {
List<RoomMember> roomMembers = roomMemberRepository.findByMemberId(memberId);
List<ClosedRoomResponseDto> closedRooms = roomMembers.stream()
.map(RoomMember::getRoom)
.filter(room -> room.getDeliveryDate().isBefore(LocalDateTime.now()))
.sorted(Comparator.comparing(Room::getDeliveryDate).reversed())
.filter(room -> {
LocalDateTime tournamentEndDate = getTournamentEndDate(room.getTournamentStartDate(), room.getTournamentDuration());
return tournamentEndDate != null && tournamentEndDate.isBefore(LocalDateTime.now());
})
.sorted(Comparator.comparing(room -> getTournamentEndDate(room.getTournamentStartDate(), room.getTournamentDuration()), Comparator.reverseOrder()))
.map(room -> mapToClosedRoomResponseDto(room, memberId))
.collect(Collectors.toList());
return closedRooms;
Expand All @@ -72,13 +76,24 @@ public List<ActiveRoomResponseDto> getActiveRoom(Long memberId) {
List<RoomMember> roomMembers = roomMemberRepository.findByMemberId(memberId);
List<ActiveRoomResponseDto> activeRooms = roomMembers.stream()
.map(RoomMember::getRoom)
.filter(room -> room.getDeliveryDate().isAfter(LocalDateTime.now()))
.filter(room -> {
LocalDateTime tournamentEndDate = getTournamentEndDate(room.getTournamentStartDate(), room.getTournamentDuration());
return tournamentEndDate != null && tournamentEndDate.isAfter(LocalDateTime.now());
})
.sorted(Comparator.comparing(room -> getRoomMemberCreationTime(room, memberId), Comparator.reverseOrder()))
.map(room -> mapToActiveRoomResponseDto(room, memberId))
.collect(Collectors.toList());
return activeRooms;
}

private LocalDateTime getTournamentEndDate(LocalDateTime tournamentStartDate, TournamentDuration tournamentDuration) {
if (tournamentStartDate != null && tournamentDuration != null) {
return tournamentStartDate.plusHours(tournamentDuration.getHours());
} else {
return null;
}
}

private ActiveRoomResponseDto mapToActiveRoomResponseDto(Room room, Long memberId) {
return new ActiveRoomResponseDto(
room.getId(),
Expand Down

0 comments on commit ffe92cb

Please sign in to comment.