Skip to content

Commit

Permalink
feat: 게시물 상태 변경 기능 추가
Browse files Browse the repository at this point in the history
- 채팅방이 닫힐 때 게시물 상태를 CLOSED로 변경하는 코드를 추가했습니다.
 - AccompanyStatusEntity에 상태 변경 메서드를 추가하고, ChatRoomServiceImpl에서 관련 로직을 구현했습니다.
  • Loading branch information
Namgyu11 committed Aug 25, 2024
1 parent 9ec8264 commit d7d3de8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ public AccompanyStatusEntity(AccompanyPostEntity accompanyPostEntity, AccompanyS
this.accompanyPostEntity = accompanyPostEntity;
this.accompanyStatusEnum = accompanyStatusEnum;
}

public void changeAccompanyStatus(AccompanyStatusEnum AccompanyStatusEnum) {
this.accompanyStatusEnum = AccompanyStatusEnum;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -31,6 +35,7 @@ public class ChatRoomServiceImpl implements ChatRoomService {
private final AccompanyPostRepository accompanyPostRepository;

private final ChatRoomMemberService chatRoomMemberService;
private final AccompanyStatusJpaRepository accompanyStatusJpaRepository;

/**
* 사용자가 참여한 채팅방 목록을 조회하여 반환하는 메서드. 주어진 사용자의 이메일 주소를 기반으로 해당 사용자가 참여한 모든 채팅방을 조회
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ public void updateAccompanyPost(String title, LocalDateTime startDate, LocalDate
this.content = content;
this.customUrl = customUrl;
}


}

0 comments on commit d7d3de8

Please sign in to comment.