Skip to content

Commit

Permalink
Fix: 일기 조회 기능 ChatID 기준과 정렬 조정
Browse files Browse the repository at this point in the history
  • Loading branch information
nonaninona committed Feb 17, 2024
1 parent bfbf95b commit 077b502
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
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")
List<Chat> 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<Chat> findTop10ByUserIdAndChatIdLessThanOrderByChatIdDesc(@Param("userId") Long userId, @Param("lastChatId") Long lastChatId);
List<Chat> findTopByMember_UserIdOrderByChatIdDesc(Long userId);
}
2 changes: 1 addition & 1 deletion src/main/java/com/kuit/chatdiary/service/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public String extractGptResponse(String jsonResponse) throws JsonProcessingExcep
}

public List<ChatGetResponseDTO> getChats(Long userId, Long lastChatId) {
List<Chat> chats = chatRepository.findTop10ByUserIdAndChatIdGreaterThanOrderByChatIdDesc(userId, lastChatId);
List<Chat> chats = chatRepository.findTop10ByUserIdAndChatIdLessThanOrderByChatIdDesc(userId, lastChatId);
if (chats.isEmpty()) {
return null;
}
Expand Down

0 comments on commit 077b502

Please sign in to comment.