diff --git a/src/main/java/connectripbe/connectrip_be/accompany_status/entity/AccompanyStatusEntity.java b/src/main/java/connectripbe/connectrip_be/accompany_status/entity/AccompanyStatusEntity.java index 20b1e13a..da52dd2e 100644 --- a/src/main/java/connectripbe/connectrip_be/accompany_status/entity/AccompanyStatusEntity.java +++ b/src/main/java/connectripbe/connectrip_be/accompany_status/entity/AccompanyStatusEntity.java @@ -29,4 +29,8 @@ public AccompanyStatusEntity(AccompanyPostEntity accompanyPostEntity, AccompanyS this.accompanyPostEntity = accompanyPostEntity; this.accompanyStatusEnum = accompanyStatusEnum; } + + public void changeAccompanyStatus(AccompanyStatusEnum AccompanyStatusEnum) { + this.accompanyStatusEnum = AccompanyStatusEnum; + } } 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 67e92fa8..0e2fa4dc 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 @@ -1,5 +1,8 @@ package connectripbe.connectrip_be.chat.service.impl; +import connectripbe.connectrip_be.accompany_status.entity.AccompanyStatusEntity; +import connectripbe.connectrip_be.accompany_status.entity.AccompanyStatusEnum; +import connectripbe.connectrip_be.accompany_status.repository.AccompanyStatusJpaRepository; import connectripbe.connectrip_be.chat.dto.ChatRoomListResponse; import connectripbe.connectrip_be.chat.dto.ChatRoomMemberResponse; import connectripbe.connectrip_be.chat.entity.ChatRoomEntity; @@ -15,6 +18,7 @@ import connectripbe.connectrip_be.global.exception.GlobalException; import connectripbe.connectrip_be.global.exception.type.ErrorCode; +import connectripbe.connectrip_be.post.exception.NotFoundAccompanyPostException; import connectripbe.connectrip_be.post.repository.AccompanyPostRepository; import jakarta.transaction.Transactional; import java.util.List; @@ -31,6 +35,7 @@ public class ChatRoomServiceImpl implements ChatRoomService { private final AccompanyPostRepository accompanyPostRepository; private final ChatRoomMemberService chatRoomMemberService; + private final AccompanyStatusJpaRepository accompanyStatusJpaRepository; /** * 사용자가 참여한 채팅방 목록을 조회하여 반환하는 메서드. 주어진 사용자의 이메일 주소를 기반으로 해당 사용자가 참여한 모든 채팅방을 조회 @@ -139,6 +144,16 @@ public void exitChatRoom(Long chatRoomId, Long memberId) { } else { // 마지막 남은 멤버가 나간 경우 채팅방 상태 변경 chatRoom.changeChatRoomType(ChatRoomType.DELETE); + + // 게시물 상태 변경 + AccompanyStatusEntity accompanyStatusEntity = accompanyStatusJpaRepository + .findTopByAccompanyPostEntityOrderByCreatedAtDesc(chatRoom.getAccompanyPost()) + .orElseThrow(NotFoundAccompanyPostException::new); + + // 채팅방이 닫히면 게시물 상태도 닫힘 + accompanyStatusEntity.changeAccompanyStatus(AccompanyStatusEnum.CLOSED); + + accompanyStatusJpaRepository.save(accompanyStatusEntity); } chatRoomRepository.save(chatRoom); diff --git a/src/main/java/connectripbe/connectrip_be/post/entity/AccompanyPostEntity.java b/src/main/java/connectripbe/connectrip_be/post/entity/AccompanyPostEntity.java index 695992aa..405aeb38 100644 --- a/src/main/java/connectripbe/connectrip_be/post/entity/AccompanyPostEntity.java +++ b/src/main/java/connectripbe/connectrip_be/post/entity/AccompanyPostEntity.java @@ -63,4 +63,6 @@ public void updateAccompanyPost(String title, LocalDateTime startDate, LocalDate this.content = content; this.customUrl = customUrl; } + + }