From 8bf270b1ea8fb20d7814aa12ff4faa34f4792b3f Mon Sep 17 00:00:00 2001 From: Jaewon Lee <58386334+jaewonLeeKOR@users.noreply.github.com> Date: Mon, 16 Sep 2024 22:26:24 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20#159=20pagination=20=EC=A0=81=EC=9A=A9?= =?UTF-8?q?=20=EC=BF=BC=EB=A6=AC=20ORDER=20BY=20=EC=A0=9C=EA=B1=B0=20?= =?UTF-8?q?=EB=B0=8F=20=EB=B0=98=ED=99=98=20=EA=B0=92=20Optional=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../capple/domain/answer/repository/AnswerRepository.java | 7 +++---- .../capple/domain/answer/service/AnswerServiceImpl.java | 3 +-- .../domain/question/repository/QuestionRepository.java | 3 +-- 3 files changed, 5 insertions(+), 8 deletions(-) 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); }