diff --git a/src/main/java/com/kuit/chatdiary/repository/ChatRepository.java b/src/main/java/com/kuit/chatdiary/repository/ChatRepository.java index 1b534bee..c7022ab5 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") + @Query("SELECT c FROM chat c WHERE c.member.userId = :userId AND c.chatId > :lastChatId ORDER BY c.chatId ASC") List findTop10ByUserIdAndChatIdGreaterThanOrderByChatIdDesc(@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..ab83de78 100644 --- a/src/main/java/com/kuit/chatdiary/service/ChatService.java +++ b/src/main/java/com/kuit/chatdiary/service/ChatService.java @@ -72,6 +72,7 @@ public String extractGptResponse(String jsonResponse) throws JsonProcessingExcep public List getChats(Long userId, Long lastChatId) { List chats = chatRepository.findTop10ByUserIdAndChatIdGreaterThanOrderByChatIdDesc(userId, lastChatId); + chats = chats.stream().limit(10).collect(Collectors.toList()); if (chats.isEmpty()) { return null; }