Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] 채팅방 목록 조회 쿼리 수정 #123

Merged
merged 1 commit into from
Jan 3, 2025
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 @@ -83,7 +83,6 @@ public Page<CompanyChatRoomListDto> getCompanyChatRoomList(User user, Pageable p
lastChatTime
);
})
.sorted(Comparator.comparing(CompanyRoomDto::getLastChatTime).reversed()) // 최신순 정렬
.toList();


Expand Down Expand Up @@ -129,7 +128,6 @@ public Page<MarketChatRoomListDto> getMarketChatRoomList(User user, Pageable pag
lastChatTime
);
})
.sorted(Comparator.comparing(MarketRoomDto::getLastChatTime).reversed()) // 최신순 정렬
.toList();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@

public interface ChattingRoomRepository extends JpaRepository<ChattingRoom, Long> {

@Query("SELECT cr FROM ChattingRoom cr WHERE (cr.chatUserOne = :user OR cr.chatUserTwo = :user) AND cr.chattingRoomType = :chattingRoomType")
@Query("SELECT cr FROM ChattingRoom cr " +
"LEFT JOIN Chat c ON c.chattingRoom = cr " +
"WHERE (cr.chatUserOne = :user OR cr.chatUserTwo = :user) " +
"AND cr.chattingRoomType = :chattingRoomType " +
"GROUP BY cr " +
"ORDER BY COALESCE(MAX(c.createdAt), cr.createdAt) DESC")
Page<ChattingRoom> findByChatUserOneOrChatUserTwoAndChattingRoomType(
@Param("user") User user,
@Param("chattingRoomType") ChatType chattingRoomType,
Expand Down