From deb0ba98e5a339df02355bae80c4716effb514a2 Mon Sep 17 00:00:00 2001 From: KyungMin Lee Date: Tue, 27 Feb 2024 14:09:55 +0900 Subject: [PATCH] =?UTF-8?q?Bug/#187=20chatroom=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95=20(#188)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [FIX] 채팅방 조회 오류 수정 * [FIX] 읽기 전용 트랜잭션 수정 --- .../chat/application/dto/res/ChatRoomPublicRes.java | 13 +++++++++++-- .../ChatRoomCustomRepositoryImpl.java | 10 ++++++---- .../domain/user/application/UserService.java | 1 + 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/oeid/mogakgo/domain/chat/application/dto/res/ChatRoomPublicRes.java b/src/main/java/io/oeid/mogakgo/domain/chat/application/dto/res/ChatRoomPublicRes.java index 6a80338e..6dda8cce 100644 --- a/src/main/java/io/oeid/mogakgo/domain/chat/application/dto/res/ChatRoomPublicRes.java +++ b/src/main/java/io/oeid/mogakgo/domain/chat/application/dto/res/ChatRoomPublicRes.java @@ -5,23 +5,32 @@ import io.swagger.v3.oas.annotations.media.Schema; import java.time.LocalDateTime; import java.util.List; -import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.Setter; @Schema(description = "채팅방 리스트 조회 응답") @Getter -@AllArgsConstructor public class ChatRoomPublicRes { @Schema(description = "프로젝트 ID") private Long projectId; @Schema(description = "채팅방 ID") private String chatRoomId; + @Setter @Schema(description = "마지막 메시지") private String lastMessage; + @Setter @Schema(description = "마지막 메시지 생성 시간") private LocalDateTime lastMessageCreatedAt; @Schema(description = "채팅방 상태") private ChatStatus status; private List profiles; + + public ChatRoomPublicRes(Long projectId, String chatRoomId, ChatStatus status, + List profiles) { + this.projectId = projectId; + this.chatRoomId = chatRoomId; + this.status = status; + this.profiles = profiles; + } } diff --git a/src/main/java/io/oeid/mogakgo/domain/chat/infrastructure/ChatRoomCustomRepositoryImpl.java b/src/main/java/io/oeid/mogakgo/domain/chat/infrastructure/ChatRoomCustomRepositoryImpl.java index 02ba1299..e2311013 100644 --- a/src/main/java/io/oeid/mogakgo/domain/chat/infrastructure/ChatRoomCustomRepositoryImpl.java +++ b/src/main/java/io/oeid/mogakgo/domain/chat/infrastructure/ChatRoomCustomRepositoryImpl.java @@ -1,12 +1,12 @@ package io.oeid.mogakgo.domain.chat.infrastructure; import static io.oeid.mogakgo.domain.chat.entity.document.QChatRoom.chatRoom; -import static io.oeid.mogakgo.domain.user.domain.QUser.user; import com.querydsl.core.types.Projections; import com.querydsl.jpa.impl.JPAQueryFactory; import io.oeid.mogakgo.domain.chat.application.dto.res.ChatRoomPublicRes; import io.oeid.mogakgo.domain.chat.application.vo.ChatUserInfo; +import io.oeid.mogakgo.domain.user.domain.QUser; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; @@ -18,13 +18,15 @@ public class ChatRoomCustomRepositoryImpl implements ChatRoomCustomRepository { private final JPAQueryFactory jpaQueryFactory; public List findAllChatRoomByUserId(Long userId) { + + QUser sender = new QUser("sender"); + QUser creator = new QUser("creator"); + return jpaQueryFactory.select( Projections.constructor( ChatRoomPublicRes.class, chatRoom.project.id, chatRoom.id, - null, - null, chatRoom.status, Projections.list(List.of( Projections.constructor( @@ -42,7 +44,7 @@ public List findAllChatRoomByUserId(Long userId) { ) ) ) - ).from(chatRoom).join(chatRoom.creator, user).join(chatRoom.sender, user) + ).from(chatRoom).join(chatRoom.creator, creator).join(chatRoom.sender, sender) .where(chatRoom.creator.id.eq(userId).or(chatRoom.sender.id.eq(userId))) .fetch(); } diff --git a/src/main/java/io/oeid/mogakgo/domain/user/application/UserService.java b/src/main/java/io/oeid/mogakgo/domain/user/application/UserService.java index c53bc647..df51884d 100644 --- a/src/main/java/io/oeid/mogakgo/domain/user/application/UserService.java +++ b/src/main/java/io/oeid/mogakgo/domain/user/application/UserService.java @@ -82,6 +82,7 @@ public UserProfileResponse getUserProfile(Long userId) { } // TODO: 이후 AchievementException 구현 시 추가 필요! + @Transactional public UserUpdateRes updateUserInfos(Long userId, UserUpdateReq request) { User user = userCommonService.getUserById(userId); Achievement achievement = achievementRepository.findById(request.getAchievementId())