From ffe92cb6ad7b764d7082e22b9f74446b3157cdb3 Mon Sep 17 00:00:00 2001 From: hysong4u Date: Sat, 20 Jan 2024 03:09:06 +0900 Subject: [PATCH] =?UTF-8?q?[fix]=20=EC=A7=84=ED=96=89=EC=A4=91,=20?= =?UTF-8?q?=EC=A2=85=EB=A3=8C=20=EC=84=A0=EB=AC=BC=EB=B0=A9=20=EB=B6=84?= =?UTF-8?q?=EB=A5=98=20=EA=B8=B0=EC=A4=80=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/gift/service/GiftService.java | 3 +++ .../domain/member/service/MemberService.java | 21 ++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) 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 416b2ec..5609cef 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 @@ -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); @@ -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); diff --git a/src/main/java/org/sopt/sweet/domain/member/service/MemberService.java b/src/main/java/org/sopt/sweet/domain/member/service/MemberService.java index a9d254f..168acfd 100644 --- a/src/main/java/org/sopt/sweet/domain/member/service/MemberService.java +++ b/src/main/java/org/sopt/sweet/domain/member/service/MemberService.java @@ -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; @@ -50,8 +51,11 @@ public List getClosedRoom(Long memberId) { List roomMembers = roomMemberRepository.findByMemberId(memberId); List 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; @@ -72,13 +76,24 @@ public List getActiveRoom(Long memberId) { List roomMembers = roomMemberRepository.findByMemberId(memberId); List 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(),