Skip to content

Commit

Permalink
Feature : MemberQuestion테이블에 없는 항목이 없을 떄 메인페이지 조회 안되는 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kojesung committed Aug 2, 2024
1 parent fb96037 commit 0249a1e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 17 additions & 7 deletions src/main/java/com/petqa/converter/MainPageConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.Optional;

@Component
@RequiredArgsConstructor
Expand All @@ -30,15 +31,24 @@ public MainPageDTO.MainPageResponseDTO tomainPageResponseDTO(Long userId){
throw new IllegalArgumentException("Pet not found");
}

UserQuestion userQuestion = userQuestionRepository.findTopByUserIdOrderByCreatedAtDesc(userId)
.orElseThrow(() -> new IllegalArgumentException("UserQuestion not found"));
Optional<UserQuestion> optionalUserQuestion = userQuestionRepository.findTopByUserIdOrderByCreatedAtDesc(userId);
//일단 유저-질문 테이블에서 해당 유저의 가장 최근 값을 가져오고

Question todayQuestion = questionRepository.findById(Long.valueOf(userQuestion.getUser().getQuestionCount()))
.orElseThrow(() -> new IllegalArgumentException("Question not found"));
LocalDate today = LocalDate.now();
Question todayQuestion;
boolean questionStatus = false;

boolean questionStatus = user.getUserQuestionsList().stream()
.anyMatch(mq -> mq.getCreatedAt().toLocalDate().equals(today));
if (optionalUserQuestion.isPresent()) {
UserQuestion userQuestion = optionalUserQuestion.get();
todayQuestion = questionRepository.findById((userQuestion.getQuestion().getId()))
.orElse(null);

LocalDate today = LocalDate.now();
questionStatus = user.getUserQuestionsList().stream()
.anyMatch(uq -> uq.getCreatedAt().toLocalDate().equals(today));
}else {
todayQuestion = questionRepository.findById(Long.valueOf(1))
.orElseThrow(()->new IllegalArgumentException("Default question not found"));
}

return MainPageDTO.MainPageResponseDTO.builder()
.petName(pet.getName())
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ spring:
jpa:
open-in-view: false
hibernate:
ddl-auto: update
ddl-auto: create-drop
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
show-sql: true
Expand Down

0 comments on commit 0249a1e

Please sign in to comment.