Skip to content

Commit

Permalink
Fix: 채팅 조회 정렬 방향 변경 및 최대 10개로 수정 (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
nonaninona authored Feb 18, 2024
1 parent bfbf95b commit 2202cdc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public interface ChatRepository extends JpaRepository<Chat, Long> {

List<Chat> findTop10ByMember_UserIdOrderByChatIdDesc(Long userId);
@Query("SELECT c FROM chat c WHERE c.member.userId = :userId AND c.chatId > :lastChatId ORDER BY c.chatId DESC")
@Query("SELECT c FROM chat c WHERE c.member.userId = :userId AND c.chatId > :lastChatId ORDER BY c.chatId ASC")
List<Chat> findTop10ByUserIdAndChatIdGreaterThanOrderByChatIdDesc(@Param("userId") Long userId, @Param("lastChatId") Long lastChatId);
List<Chat> findTopByMember_UserIdOrderByChatIdDesc(Long userId);
}
1 change: 1 addition & 0 deletions src/main/java/com/kuit/chatdiary/service/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public String extractGptResponse(String jsonResponse) throws JsonProcessingExcep

public List<ChatGetResponseDTO> getChats(Long userId, Long lastChatId) {
List<Chat> chats = chatRepository.findTop10ByUserIdAndChatIdGreaterThanOrderByChatIdDesc(userId, lastChatId);
chats = chats.stream().limit(10).collect(Collectors.toList());
if (chats.isEmpty()) {
return null;
}
Expand Down

0 comments on commit 2202cdc

Please sign in to comment.