From f3927540816da4862127913c0216d6c4cd3695a2 Mon Sep 17 00:00:00 2001 From: Namgyu11 <103015031+Namgyu11@users.noreply.github.com> Date: Mon, 26 Aug 2024 16:39:58 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=B1=84=ED=8C=85=EB=B0=A9=20=EB=82=98?= =?UTF-8?q?=EA=B0=80=EA=B8=B0=20=EC=8B=9C=20pendingList=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EB=B0=8F=20=ED=99=9C=EC=84=B1=20?= =?UTF-8?q?=EB=A9=A4=EB=B2=84=20=EC=88=98=20=EA=B3=84=EC=82=B0=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 채팅방에서 나가기 전 pendingList를 업데이트하는 로직 추가. - ChatRoomListResponse에 활성 멤버 수 계산 기능 추가. - 이에 따라 ChatRoomListResponse의 memberNumber 필드 수정. --- .../connectrip_be/chat/dto/ChatRoomListResponse.java | 8 +++++++- .../chat/service/impl/ChatRoomServiceImpl.java | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/connectripbe/connectrip_be/chat/dto/ChatRoomListResponse.java b/src/main/java/connectripbe/connectrip_be/chat/dto/ChatRoomListResponse.java index 350a965a..e1a65452 100644 --- a/src/main/java/connectripbe/connectrip_be/chat/dto/ChatRoomListResponse.java +++ b/src/main/java/connectripbe/connectrip_be/chat/dto/ChatRoomListResponse.java @@ -2,6 +2,7 @@ import connectripbe.connectrip_be.chat.entity.ChatRoomEntity; +import connectripbe.connectrip_be.chat.entity.type.ChatRoomMemberStatus; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; @@ -28,6 +29,11 @@ public static ChatRoomListResponse fromEntity(ChatRoomEntity chatRoom) { ? chatRoom.getLastChatTime() : chatRoom.getCreatedAt(); + // 활성 멤버 수 계산 + int activeMemberCnt = (int) chatRoom.getChatRoomMembers().stream() + .filter(member -> member.getStatus().equals(ChatRoomMemberStatus.ACTIVE)) + .count(); + return ChatRoomListResponse.builder() .chatRoomId(chatRoom.getId()) .accompanyPostId(chatRoom.getAccompanyPost().getId()) @@ -37,7 +43,7 @@ public static ChatRoomListResponse fromEntity(ChatRoomEntity chatRoom) { .endDate(formatToUTC(chatRoom.getAccompanyPost().getEndDate())) .lastChatMessage(chatRoom.getLastChatMessage()) .lastChatMessageTime(formatToUTC(lastChatTime)) - .memberNumber(chatRoom.getChatRoomMembers().size()) + .memberNumber(activeMemberCnt) .build(); } diff --git a/src/main/java/connectripbe/connectrip_be/chat/service/impl/ChatRoomServiceImpl.java b/src/main/java/connectripbe/connectrip_be/chat/service/impl/ChatRoomServiceImpl.java index 0a66de99..129443ea 100644 --- a/src/main/java/connectripbe/connectrip_be/chat/service/impl/ChatRoomServiceImpl.java +++ b/src/main/java/connectripbe/connectrip_be/chat/service/impl/ChatRoomServiceImpl.java @@ -130,6 +130,9 @@ public void exitChatRoom(Long chatRoomId, Long memberId) { // 사용자가 존재하는지 확인 ChatRoomMemberEntity chatRoomMember = getRoomMember(chatRoomId, memberId); + // 채팅방에서 나가기 전 pendingList 업데이트 + pendingListUpdate(chatRoomMember, chatRoom); + // 사용자가 채팅방에서 나가기 chatRoomMember.exitChatRoom(); @@ -163,12 +166,13 @@ public void exitChatRoom(Long chatRoomId, Long memberId) { chatRoomRepository.save(chatRoom); + } + + private void pendingListUpdate(ChatRoomMemberEntity chatRoomMember, ChatRoomEntity chatRoom) { AccompanyPostEntity accompanyPost = chatRoomMember.getChatRoom().getAccompanyPost(); // 방장이 아닌 경우에만 pendingList 업데이트 if (!chatRoomMember.getMember().equals(chatRoom.getCurrentLeader().getMember())) { - - // 채팅방 나가기 처리 후, 방장이 아닌 일반 사용자가 참여한 pendingList EXIT_ROOM 으로 변경 PendingListEntity pendingMember = pendingListRepository.findByAccompanyPostAndMember( accompanyPost, chatRoomMember.getMember()) .orElseThrow(() -> new GlobalException(ErrorCode.PENDING_LIST_NOT_FOUND));