Skip to content

Commit

Permalink
Fix: 채팅 조회시 userId 적용 (#59)
Browse files Browse the repository at this point in the history
* Fix: 채팅 조회시 userId 적용

user별 채팅 가져오기 위함

* Fix: 일기 스트릭 수정(일기 하나도 없는 경우)
  • Loading branch information
dainshon authored Feb 16, 2024
1 parent 1f2a4c2 commit bfbf95b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
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

0 comments on commit bfbf95b

Please sign in to comment.