Skip to content

Commit

Permalink
Merge pull request #123 from UMC-ON/feat/chat
Browse files Browse the repository at this point in the history
[Fix] 채팅방 목록 조회 쿼리 수정
  • Loading branch information
Haewonny authored Jan 3, 2025
2 parents 6633195 + 11f85f8 commit 28ecb34
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
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

0 comments on commit 28ecb34

Please sign in to comment.