diff --git a/src/main/java/com/server/capple/domain/answer/repository/AnswerRepository.java b/src/main/java/com/server/capple/domain/answer/repository/AnswerRepository.java index cbd5770a..088f3054 100644 --- a/src/main/java/com/server/capple/domain/answer/repository/AnswerRepository.java +++ b/src/main/java/com/server/capple/domain/answer/repository/AnswerRepository.java @@ -24,12 +24,11 @@ public interface AnswerRepository extends JpaRepository { "FROM Answer a " + "LEFT JOIN " + "Report r ON r.answer = a " + - "WHERE a.question.id = :questionId " + - "ORDER BY a.createdAt DESC") - Optional> findByQuestion( + "WHERE a.question.id = :questionId") + Slice findByQuestion( @Param("questionId") Long questionId, Pageable pageable); - @Query("SELECT a FROM Answer a WHERE a.member = :member and a.deletedAt is null ORDER BY a.createdAt DESC") + @Query("SELECT a FROM Answer a WHERE a.member = :member and a.deletedAt is null") Slice findByMember(@Param("member") Member member, Pageable pageable); } diff --git a/src/main/java/com/server/capple/domain/answer/service/AnswerServiceImpl.java b/src/main/java/com/server/capple/domain/answer/service/AnswerServiceImpl.java index 10d37036..5efc4eec 100644 --- a/src/main/java/com/server/capple/domain/answer/service/AnswerServiceImpl.java +++ b/src/main/java/com/server/capple/domain/answer/service/AnswerServiceImpl.java @@ -93,8 +93,7 @@ public AnswerLike toggleAnswerHeart(Member loginMember, Long answerId) { @Override public SliceResponse getAnswerList(Long memberId, Long questionId, Pageable pageable) { - Slice answerInfoSliceInterface = answerRepository.findByQuestion(questionId, pageable).orElseThrow(() - -> new RestApiException(AnswerErrorCode.ANSWER_NOT_FOUND)); + Slice answerInfoSliceInterface = answerRepository.findByQuestion(questionId, pageable); return SliceResponse.toSliceResponse(answerInfoSliceInterface, answerInfoSliceInterface.getContent().stream().map( answerInfoDto -> answerMapper.toAnswerInfo( answerInfoDto.getAnswer(), diff --git a/src/main/java/com/server/capple/domain/question/repository/QuestionRepository.java b/src/main/java/com/server/capple/domain/question/repository/QuestionRepository.java index 928d4399..419e7d7f 100644 --- a/src/main/java/com/server/capple/domain/question/repository/QuestionRepository.java +++ b/src/main/java/com/server/capple/domain/question/repository/QuestionRepository.java @@ -23,8 +23,7 @@ public interface QuestionRepository extends JpaRepository { @Query("SELECT q AS question, (a IS NOT NULL) AS isAnsweredByMember " + "FROM Question q LEFT JOIN Answer a ON q = a.question AND a.deletedAt is NULL AND a.member = :member " + - "WHERE q.questionStatus = 'OLD' OR q.questionStatus = 'LIVE' " + - "ORDER BY q.livedAt DESC") + "WHERE q.questionStatus = 'OLD' OR q.questionStatus = 'LIVE'") Slice findAllByQuestionStatusIsLiveAndOldOrderByLivedAtDesc(@Param("member") Member member, Pageable pageable); }