Skip to content

Commit

Permalink
feat: #159 pagination 적용 쿼리 ORDER BY 제거 및 반환 값 Optional 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
jaewonLeeKOR committed Sep 16, 2024
1 parent 85117a2 commit 8bf270b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ public interface AnswerRepository extends JpaRepository<Answer, Long> {
"FROM Answer a " +
"LEFT JOIN " +
"Report r ON r.answer = a " +
"WHERE a.question.id = :questionId " +
"ORDER BY a.createdAt DESC")
Optional<Slice<AnswerInfoInterface>> findByQuestion(
"WHERE a.question.id = :questionId")
Slice<AnswerInfoInterface> 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<Answer> findByMember(@Param("member") Member member, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ public AnswerLike toggleAnswerHeart(Member loginMember, Long answerId) {

@Override
public SliceResponse<AnswerInfo> getAnswerList(Long memberId, Long questionId, Pageable pageable) {
Slice<AnswerInfoInterface> answerInfoSliceInterface = answerRepository.findByQuestion(questionId, pageable).orElseThrow(()
-> new RestApiException(AnswerErrorCode.ANSWER_NOT_FOUND));
Slice<AnswerInfoInterface> answerInfoSliceInterface = answerRepository.findByQuestion(questionId, pageable);
return SliceResponse.toSliceResponse(answerInfoSliceInterface, answerInfoSliceInterface.getContent().stream().map(
answerInfoDto -> answerMapper.toAnswerInfo(
answerInfoDto.getAnswer(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public interface QuestionRepository extends JpaRepository<Question, Long> {

@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<QuestionInfoInterface> findAllByQuestionStatusIsLiveAndOldOrderByLivedAtDesc(@Param("member") Member member, Pageable pageable);

}
Expand Down

0 comments on commit 8bf270b

Please sign in to comment.