diff --git a/src/main/java/com/kuit/chatdiary/repository/ChatRepository.java b/src/main/java/com/kuit/chatdiary/repository/ChatRepository.java index 1b534bee..e516bf13 100644 --- a/src/main/java/com/kuit/chatdiary/repository/ChatRepository.java +++ b/src/main/java/com/kuit/chatdiary/repository/ChatRepository.java @@ -10,7 +10,7 @@ public interface ChatRepository extends JpaRepository { List findTop10ByMember_UserIdOrderByChatIdDesc(Long userId); - @Query("SELECT c FROM chat c WHERE c.member.userId = :userId AND c.chatId > :lastChatId ORDER BY c.chatId DESC") - List findTop10ByUserIdAndChatIdGreaterThanOrderByChatIdDesc(@Param("userId") Long userId, @Param("lastChatId") Long lastChatId); + @Query("SELECT c FROM chat c WHERE c.member.userId = :userId AND c.chatId < :lastChatId ORDER BY c.chatId ASC") + List findTop10ByUserIdAndChatIdLessThanOrderByChatIdDesc(@Param("userId") Long userId, @Param("lastChatId") Long lastChatId); List findTopByMember_UserIdOrderByChatIdDesc(Long userId); } diff --git a/src/main/java/com/kuit/chatdiary/service/ChatService.java b/src/main/java/com/kuit/chatdiary/service/ChatService.java index 5f558f51..d84e7ceb 100644 --- a/src/main/java/com/kuit/chatdiary/service/ChatService.java +++ b/src/main/java/com/kuit/chatdiary/service/ChatService.java @@ -71,7 +71,7 @@ public String extractGptResponse(String jsonResponse) throws JsonProcessingExcep } public List getChats(Long userId, Long lastChatId) { - List chats = chatRepository.findTop10ByUserIdAndChatIdGreaterThanOrderByChatIdDesc(userId, lastChatId); + List chats = chatRepository.findTop10ByUserIdAndChatIdLessThanOrderByChatIdDesc(userId, lastChatId); if (chats.isEmpty()) { return null; }