Skip to content

Commit 55dc41d

Browse files
committed
[fix]: 채팅 목록 조회 수정
- 요청한 채팅방과 요청받은 채팅방 모두 조회 가능하도록 수정
1 parent 58bc819 commit 55dc41d

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/main/java/org/dfbf/soundlink/domain/chat/repository/ChatRoomCustomRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88
public interface ChatRoomCustomRepository {
99
Optional<Long> findChatRoomIdByRequestUserIdAndRecordId(Long requestUserId, Long recordId);
1010
List<ChatRoom> findByRequestUserIdOrderByCreatedAtDesc(Long userId);
11+
List<ChatRoom> findByRequestUserIdOrRecordId_User_UserIdOrderByCreatedAtDesc(Long userId);
12+
1113
}

src/main/java/org/dfbf/soundlink/domain/chat/repository/ChatRoomRepositoryImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.dfbf.soundlink.domain.chat.entity.ChatRoom;
66
import org.dfbf.soundlink.domain.chat.entity.QChatRoom;
77
import org.dfbf.soundlink.domain.emotionRecord.entity.EmotionRecord;
8+
import org.dfbf.soundlink.domain.emotionRecord.entity.QEmotionRecord;
89
import org.dfbf.soundlink.domain.user.entity.QProfileMusic;
910
import org.dfbf.soundlink.domain.user.entity.QUser;
1011
import org.dfbf.soundlink.domain.user.entity.User;
@@ -40,4 +41,19 @@ public List<ChatRoom> findByRequestUserIdOrderByCreatedAtDesc(Long userId) {
4041
.orderBy(QChatRoom.chatRoom.createdAt.desc())
4142
.fetch();
4243
}
44+
45+
@Override
46+
public List<ChatRoom> findByRequestUserIdOrRecordId_User_UserIdOrderByCreatedAtDesc(Long userId) {
47+
return queryFactory
48+
.selectFrom(QChatRoom.chatRoom)
49+
.leftJoin(QChatRoom.chatRoom.recordId, QEmotionRecord.emotionRecord) // ChatRoom과 EmotionRecord를 left join
50+
.leftJoin(QEmotionRecord.emotionRecord.user, QUser.user) // EmotionRecord와 User를 left join
51+
.where(
52+
QChatRoom.chatRoom.requestUserId.userId.eq(userId) // 요청자 userId 기준
53+
.or(QUser.user.userId.eq(userId)) // 응답자 userId 기준
54+
)
55+
.orderBy(QChatRoom.chatRoom.createdAt.desc()) // 생성일 기준 내림차순 정렬
56+
.fetch();
57+
}
58+
4359
}

src/main/java/org/dfbf/soundlink/domain/chat/service/ChatRoomService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public ResponseResult closeChatRoom(@AuthenticationPrincipal Long userId, Long c
295295
//채팅방 목록 불러오기
296296
public ResponseResult getChatRoomList(@AuthenticationPrincipal Long userId) {
297297
try {
298-
List<ChatRoom> chatRooms = chatRoomRepository.findByRequestUserIdOrderByCreatedAtDesc(userId);
298+
List<ChatRoom> chatRooms = chatRoomRepository.findByRequestUserIdOrRecordId_User_UserIdOrderByCreatedAtDesc(userId);
299299

300300
List<ChatRoomListDto> chatRoomList = chatRooms.stream()
301301
.map(chatRoom -> new ChatRoomListDto(

0 commit comments

Comments
 (0)