diff --git a/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatRoomSimpleResponse.java b/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatRoomSimpleResponse.java index 7f80c1bb..136b893c 100644 --- a/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatRoomSimpleResponse.java +++ b/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatRoomSimpleResponse.java @@ -2,10 +2,11 @@ import com.dnd.gongmuin.question_post.dto.response.MemberInfo; -public record ChatRoomSimpleResponse ( +public record ChatRoomSimpleResponse( Long chatRoomId, MemberInfo chatPartner, String latestMessage, String messageType, String messageCreatedAt -){} +) { +} diff --git a/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepositoryImpl.java b/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepositoryImpl.java index ee28194f..80aa490f 100644 --- a/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepositoryImpl.java +++ b/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepositoryImpl.java @@ -15,6 +15,7 @@ @RequiredArgsConstructor public class ChatRoomQueryRepositoryImpl implements ChatRoomQueryRepository { private final JPAQueryFactory queryFactory; + public List getChatRoomsByMember(Member member) { return queryFactory .select(new QChatRoomInfo( diff --git a/src/main/java/com/dnd/gongmuin/chat/service/ChatRoomService.java b/src/main/java/com/dnd/gongmuin/chat/service/ChatRoomService.java index 7e2a8f51..69dced06 100644 --- a/src/main/java/com/dnd/gongmuin/chat/service/ChatRoomService.java +++ b/src/main/java/com/dnd/gongmuin/chat/service/ChatRoomService.java @@ -85,18 +85,21 @@ public List getChatRoomsByMember(Member member) { .map(ChatRoomInfo::chatRoomId) .toList(); // 각 채팅방 최근 메시지 정보 - List latestChatMessages = chatMessageQueryRepository.findLatestChatByChatRoomIds(chatRoomIds); + List latestChatMessages = chatMessageQueryRepository.findLatestChatByChatRoomIds( + chatRoomIds); // -> 순서 보장 x Map messageMap = latestChatMessages.stream() .collect(Collectors.toMap(LatestChatMessage::chatRoomId, message -> message)); // 최신순 정렬 return chatRoomInfos.stream() - .sorted(Comparator.comparing((ChatRoomInfo info) -> messageMap.get(info.chatRoomId()).createdAt()).reversed()) + .sorted( + Comparator.comparing((ChatRoomInfo info) -> messageMap.get(info.chatRoomId()).createdAt()).reversed()) .map(chatRoomInfo -> { LatestChatMessage latestMessage = messageMap.get(chatRoomInfo.chatRoomId()); return new ChatRoomSimpleResponse( chatRoomInfo.chatRoomId(), - new MemberInfo(chatRoomInfo.partnerId(), chatRoomInfo.partnerNickname(), chatRoomInfo.partnerJobGroup(), chatRoomInfo.partnerProfileImageNo()), + new MemberInfo(chatRoomInfo.partnerId(), chatRoomInfo.partnerNickname(), + chatRoomInfo.partnerJobGroup(), chatRoomInfo.partnerProfileImageNo()), latestMessage.content(), latestMessage.type(), latestMessage.createdAt().toString() diff --git a/src/main/java/com/dnd/gongmuin/member/domain/Member.java b/src/main/java/com/dnd/gongmuin/member/domain/Member.java index 37e77af5..87b1ce57 100644 --- a/src/main/java/com/dnd/gongmuin/member/domain/Member.java +++ b/src/main/java/com/dnd/gongmuin/member/domain/Member.java @@ -62,16 +62,6 @@ private Member(String nickname, String socialName, JobGroup jobGroup, JobCategor this.role = role; } - @Override - public String toString() { - return "MEMBER INFO{" + - "id=" + id + - ", role='" + role + '\'' + - ", jobGroup=" + jobGroup + - ", socialEmail='" + socialEmail + '\'' + - '}'; - } - public static Member of(String socialName, String socialEmail, int credit) { return Member.builder() .socialName(socialName) @@ -103,6 +93,16 @@ public static Member of(String nickname, String socialName, JobGroup jobGroup, J .build(); } + @Override + public String toString() { + return "MEMBER INFO{" + + "id=" + id + + ", role='" + role + '\'' + + ", jobGroup=" + jobGroup + + ", socialEmail='" + socialEmail + '\'' + + '}'; + } + public void updateSocialEmail(String socialEmail) { this.socialEmail = socialEmail; }