Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
public interface ChatRoomCustomRepository {
Optional<Long> findChatRoomIdByRequestUserIdAndRecordId(Long requestUserId, Long recordId);
List<ChatRoom> findByRequestUserIdOrderByCreatedAtDesc(Long userId);
List<ChatRoom> findChatRoomsByUserId(Long userId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.dfbf.soundlink.domain.chat.entity.ChatRoom;
import org.dfbf.soundlink.domain.chat.entity.QChatRoom;
import org.dfbf.soundlink.domain.emotionRecord.entity.EmotionRecord;
import org.dfbf.soundlink.domain.emotionRecord.entity.QEmotionRecord;
import org.dfbf.soundlink.domain.user.entity.QProfileMusic;
import org.dfbf.soundlink.domain.user.entity.QUser;
import org.dfbf.soundlink.domain.user.entity.User;
Expand Down Expand Up @@ -40,4 +41,19 @@ public List<ChatRoom> findByRequestUserIdOrderByCreatedAtDesc(Long userId) {
.orderBy(QChatRoom.chatRoom.createdAt.desc())
.fetch();
}

@Override
public List<ChatRoom> findChatRoomsByUserId(Long userId) {
return queryFactory
.selectFrom(QChatRoom.chatRoom)
.leftJoin(QChatRoom.chatRoom.recordId, QEmotionRecord.emotionRecord) // ChatRoom과 EmotionRecord를 left join
.leftJoin(QEmotionRecord.emotionRecord.user, QUser.user) // EmotionRecord와 User를 left join
.where(
QChatRoom.chatRoom.requestUserId.userId.eq(userId) // 요청자 userId 기준
.or(QUser.user.userId.eq(userId)) // 응답자 userId 기준
)
.orderBy(QChatRoom.chatRoom.createdAt.desc()) // 생성일 기준 내림차순 정렬
.fetch();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public ResponseResult deleteRequestFromRedis(Long userId, Long emotionRecordId)
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER);
} catch (Exception e) {
log.error(e.getMessage());
return new ResponseResult(400, "Chat request failed.");
return new ResponseResult(400, "Failed to delete the chat request.");
}
}

Expand Down Expand Up @@ -182,7 +182,7 @@ public ResponseResult requestRejected(Long responseUserId, ChatRejectDto chatRej
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER);
} catch (Exception e) {
log.error(e.getMessage());
return new ResponseResult(400, "Chat request failed.");
return new ResponseResult(400, "Failed to reject the chat request.");
}
}

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

List<ChatRoomListDto> chatRoomList = chatRooms.stream()
.map(chatRoom -> new ChatRoomListDto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void testGetChatRoomList() {

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

when(chatRoomRepository.findByRequestUserIdOrderByCreatedAtDesc(userId)).thenReturn(mockChatRooms);
when(chatRoomRepository.findChatRoomsByUserId(userId)).thenReturn(mockChatRooms);

//when
ResponseResult result = chatRoomService.getChatRoomList(userId);
Expand Down
Loading