Skip to content

Commit

Permalink
Merge pull request #87 from 100-hours-a-week/fix-postStatus
Browse files Browse the repository at this point in the history
fix-postStatus
  • Loading branch information
sen2y authored Aug 25, 2024
2 parents 15e097a + d7d3de8 commit 4bbe27c
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 4bbe27c

Please sign in to comment.