Skip to content

Commit 3f93ec2

Browse files
authored
Merge pull request #92 from fix/chatRoom/4
[fix]: 채팅 목록 조회 수정
2 parents f9b3016 + d87fa23 commit 3f93ec2

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
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> findChatRoomsByUserId(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> findChatRoomsByUserId(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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public ResponseResult deleteRequestFromRedis(Long userId, Long emotionRecordId)
146146
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER);
147147
} catch (Exception e) {
148148
log.error(e.getMessage());
149-
return new ResponseResult(400, "Chat request failed.");
149+
return new ResponseResult(400, "Failed to delete the chat request.");
150150
}
151151
}
152152

@@ -182,7 +182,7 @@ public ResponseResult requestRejected(Long responseUserId, ChatRejectDto chatRej
182182
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER);
183183
} catch (Exception e) {
184184
log.error(e.getMessage());
185-
return new ResponseResult(400, "Chat request failed.");
185+
return new ResponseResult(400, "Failed to reject the chat request.");
186186
}
187187
}
188188

@@ -297,7 +297,7 @@ public ResponseResult closeChatRoom(@AuthenticationPrincipal Long userId, Long c
297297
//채팅방 목록 불러오기
298298
public ResponseResult getChatRoomList(@AuthenticationPrincipal Long userId) {
299299
try {
300-
List<ChatRoom> chatRooms = chatRoomRepository.findByRequestUserIdOrderByCreatedAtDesc(userId);
300+
List<ChatRoom> chatRooms = chatRoomRepository.findChatRoomsByUserId(userId);
301301

302302
List<ChatRoomListDto> chatRoomList = chatRooms.stream()
303303
.map(chatRoom -> new ChatRoomListDto(

src/test/java/org/dfbf/soundlink/domain/chatRoom/ChatRoomServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ void testGetChatRoomList() {
307307

308308
List<ChatRoom> mockChatRooms = List.of(mockChatRoom);
309309

310-
when(chatRoomRepository.findByRequestUserIdOrderByCreatedAtDesc(userId)).thenReturn(mockChatRooms);
310+
when(chatRoomRepository.findChatRoomsByUserId(userId)).thenReturn(mockChatRooms);
311311

312312
//when
313313
ResponseResult result = chatRoomService.getChatRoomList(userId);

0 commit comments

Comments
 (0)