Skip to content

Commit

Permalink
Hotfix: 채팅 조회 API 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
nonaninona committed Feb 19, 2024
1 parent 5dc9d9f commit 7b77cf4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 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 ASC")
@Query("SELECT c FROM chat c WHERE c.member.userId = :userId AND :lastChatId <= c.chatId AND c.chatId < :lastChatId+10 ORDER BY c.chatId ASC")
List<Chat> findTop10ByUserIdAndChatIdGreaterThanOrderByChatIdDesc(@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 @@ -72,7 +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());
System.out.println(chats);
if (chats.isEmpty()) {
return null;
}
Expand Down

0 comments on commit 7b77cf4

Please sign in to comment.