From 3c1deb0fdfebe00f479a8d152966980e8891d81a Mon Sep 17 00:00:00 2001 From: Namgyu11 <103015031+Namgyu11@users.noreply.github.com> Date: Mon, 26 Aug 2024 13:54:36 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EC=B1=84=ED=8C=85=EB=B0=A9=20ID?= =?UTF-8?q?=EB=A5=BC=20=EB=8F=99=EB=B0=98=20=EA=B2=8C=EC=8B=9C=EB=AC=BC=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=EC=97=90=20=ED=8F=AC=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AccompanyPostResponse에 채팅방 정보를 추가하여 채팅방 ID를 포함하게 했습니다. - ChatRoomRepository에 findByAccompanyPost_Id 메서드를 추가했습니다. - 읽기 및 업데이트시 채팅방 정보를 함께 가져오도록 서비스 로직을 수정했습니다. --- .../chat/repository/ChatRoomRepository.java | 3 +++ .../post/dto/AccompanyPostResponse.java | 9 +++++++-- .../service/impl/AccompanyPostServiceImpl.java | 16 ++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/java/connectripbe/connectrip_be/chat/repository/ChatRoomRepository.java b/src/main/java/connectripbe/connectrip_be/chat/repository/ChatRoomRepository.java index 1a05e9ec..6f34bded 100644 --- a/src/main/java/connectripbe/connectrip_be/chat/repository/ChatRoomRepository.java +++ b/src/main/java/connectripbe/connectrip_be/chat/repository/ChatRoomRepository.java @@ -2,9 +2,12 @@ import connectripbe.connectrip_be.chat.entity.ChatRoomEntity; import java.util.List; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository public interface ChatRoomRepository extends JpaRepository { + + Optional findByAccompanyPost_Id(long id); } diff --git a/src/main/java/connectripbe/connectrip_be/post/dto/AccompanyPostResponse.java b/src/main/java/connectripbe/connectrip_be/post/dto/AccompanyPostResponse.java index 99e1e5ca..fd7f319b 100644 --- a/src/main/java/connectripbe/connectrip_be/post/dto/AccompanyPostResponse.java +++ b/src/main/java/connectripbe/connectrip_be/post/dto/AccompanyPostResponse.java @@ -1,5 +1,6 @@ package connectripbe.connectrip_be.post.dto; +import connectripbe.connectrip_be.chat.entity.ChatRoomEntity; import connectripbe.connectrip_be.post.entity.AccompanyPostEntity; import lombok.Builder; @@ -11,6 +12,7 @@ public record AccompanyPostResponse( Long id, Long memberId, + Long leaderId, String nickname, String profileImagePath, String title, @@ -24,11 +26,13 @@ public record AccompanyPostResponse( String createdAt ) { - public static AccompanyPostResponse fromEntity(AccompanyPostEntity accompanyPost, String status) { + public static AccompanyPostResponse fromEntity(AccompanyPostEntity accompanyPost, String status + , ChatRoomEntity chatRoom) { return AccompanyPostResponse.builder() .id(accompanyPost.getId()) .memberId(accompanyPost.getMemberEntity().getId()) + .leaderId(chatRoom.getCurrentLeader().getMember().getId()) .nickname(accompanyPost.getMemberEntity().getNickname()) .profileImagePath(accompanyPost.getMemberEntity().getProfileImagePath()) .title(accompanyPost.getTitle()) @@ -44,7 +48,8 @@ public static AccompanyPostResponse fromEntity(AccompanyPostEntity accompanyPost } - private static final DateTimeFormatter UTC_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"); + private static final DateTimeFormatter UTC_FORMATTER = DateTimeFormatter.ofPattern( + "yyyy-MM-dd'T'HH:mm:ss'Z'"); private static String formatToUTC(LocalDateTime dateTime) { if (dateTime == null) { diff --git a/src/main/java/connectripbe/connectrip_be/post/service/impl/AccompanyPostServiceImpl.java b/src/main/java/connectripbe/connectrip_be/post/service/impl/AccompanyPostServiceImpl.java index acffec67..e6516922 100644 --- a/src/main/java/connectripbe/connectrip_be/post/service/impl/AccompanyPostServiceImpl.java +++ b/src/main/java/connectripbe/connectrip_be/post/service/impl/AccompanyPostServiceImpl.java @@ -3,7 +3,11 @@ 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.entity.ChatRoomEntity; +import connectripbe.connectrip_be.chat.repository.ChatRoomRepository; import connectripbe.connectrip_be.chat.service.ChatRoomService; +import connectripbe.connectrip_be.global.exception.GlobalException; +import connectripbe.connectrip_be.global.exception.type.ErrorCode; import connectripbe.connectrip_be.member.exception.MemberNotOwnerException; import connectripbe.connectrip_be.member.exception.NotFoundMemberException; import connectripbe.connectrip_be.post.dto.*; @@ -31,6 +35,7 @@ public class AccompanyPostServiceImpl implements AccompanyPostService { private final AccompanyStatusJpaRepository accompanyStatusJpaRepository; private final ChatRoomService chatRoomService; + private final ChatRoomRepository chatRoomRepository; @Override @Transactional @@ -66,12 +71,16 @@ public void createAccompanyPost(Long memberId, CreateAccompanyPostRequest reques @Transactional(readOnly = true) public AccompanyPostResponse readAccompanyPost(long id) { AccompanyPostEntity accompanyPostEntity = findAccompanyPostEntity(id); + AccompanyStatusEntity accompanyStatusEntity = accompanyStatusJpaRepository .findTopByAccompanyPostEntityOrderByCreatedAtDesc(accompanyPostEntity) .orElseThrow(NotFoundAccompanyPostException::new); + ChatRoomEntity chatRoom = chatRoomRepository.findByAccompanyPost_Id(id) + .orElseThrow(() -> new GlobalException(ErrorCode.CHAT_ROOM_NOT_FOUND)); + return AccompanyPostResponse.fromEntity(accompanyPostEntity, - accompanyStatusEntity.getAccompanyStatusEnum().toString()); + accompanyStatusEntity.getAccompanyStatusEnum().toString(), chatRoom); } @Override @@ -96,9 +105,12 @@ public AccompanyPostResponse updateAccompanyPost(Long memberId, long id, request.customUrl() ); + ChatRoomEntity chatRoom = chatRoomRepository.findByAccompanyPost_Id(id) + .orElseThrow(() -> new GlobalException(ErrorCode.CHAT_ROOM_NOT_FOUND)); + // 수정된 데이터를 응답으로 반환 return AccompanyPostResponse.fromEntity(accompanyPostEntity, accompanyStatusEntity - .getAccompanyStatusEnum().toString()); + .getAccompanyStatusEnum().toString(), chatRoom); } @Override From c8007b417b2ea1e7331407e7727b344575105760 Mon Sep 17 00:00:00 2001 From: Namgyu11 <103015031+Namgyu11@users.noreply.github.com> Date: Mon, 26 Aug 2024 13:55:13 +0900 Subject: [PATCH 2/2] =?UTF-8?q?add:=20MongoDB=20=EB=B0=8F=20RabbitMQ=20?= =?UTF-8?q?=EB=9D=BC=EC=9D=B4=EB=B8=8C=EB=9F=AC=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - MongoDB 데이터베이스 연동을 위한 spring-boot-starter-data-mongodb 라이브러리를 추가했습니다. - RabbitMQ 메시지 큐 연동을 위한 spring-boot-starter-amqp 라이브러리를 추가했습니다. --- build.gradle | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build.gradle b/build.gradle index 9fd6c661..8167104f 100644 --- a/build.gradle +++ b/build.gradle @@ -76,6 +76,14 @@ dependencies { annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta" annotationProcessor "jakarta.annotation:jakarta.annotation-api" annotationProcessor "jakarta.persistence:jakarta.persistence-api" + + // MongoDB + implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' + + // RabbitMQ + implementation 'org.springframework.boot:spring-boot-starter-amqp' + + // STOMP } tasks.named('bootBuildImage') {