Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: 채팅 조회시 userId 적용 #59

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public class ChatController {
private ChatService chatService;

@GetMapping("/get")
public ResponseEntity<List<ChatGetResponseDTO>> getChats(@RequestParam Long chatId) {
List<ChatGetResponseDTO> chats = chatService.getChats(chatId);
public ResponseEntity<List<ChatGetResponseDTO>> getChats(@RequestParam Long userId, @RequestParam Long chatId) {
List<ChatGetResponseDTO> chats = chatService.getChats(userId, chatId);
if (chats == null) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(Collections.emptyList());
}
return ResponseEntity.ok(chatService.getChats(chatId));
return ResponseEntity.ok(chatService.getChats(userId, chatId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import com.kuit.chatdiary.domain.Chat;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ChatRepository extends JpaRepository<Chat, Long> {

List<Chat> findTop10ByMember_UserIdOrderByChatIdDesc(Long userId);
List<Chat> findTop10ByChatIdGreaterThan(Long lastChatId);
@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);
List<Chat> findTopByMember_UserIdOrderByChatIdDesc(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ public Long streakDate(long userId, LocalDate today){
/**
* 조회 기준 날짜 하루전으로 일기 스트릭 인정해줌
* */
if (diaries.isEmpty() || !diaries.get(0).getDiaryDate().toLocalDate().equals(today.minusDays(1))) {
if(diaries.get(0).getDiaryDate().toLocalDate().equals(today)){

}else{
if (diaries.isEmpty()) {
return 0L;
}
if(!diaries.get(0).getDiaryDate().toLocalDate().equals(today.minusDays(1))) {
if(!diaries.get(0).getDiaryDate().toLocalDate().equals(today)) {
return 0L;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/kuit/chatdiary/service/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public String extractGptResponse(String jsonResponse) throws JsonProcessingExcep
return "";
}

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