From d5303fb8d937ac8c3a17e915f41fc108236ecd93 Mon Sep 17 00:00:00 2001 From: dhkstnaos Date: Thu, 1 Dec 2022 18:31:59 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infra/QuestionSearchRepositoryImpl.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/developer/wiki/question/infra/QuestionSearchRepositoryImpl.java b/src/main/java/com/developer/wiki/question/infra/QuestionSearchRepositoryImpl.java index c37a8fa..ab14cab 100644 --- a/src/main/java/com/developer/wiki/question/infra/QuestionSearchRepositoryImpl.java +++ b/src/main/java/com/developer/wiki/question/infra/QuestionSearchRepositoryImpl.java @@ -1,6 +1,9 @@ package com.developer.wiki.question.infra; +import static com.developer.wiki.bookmark.QBookmark.bookmark; +import static com.developer.wiki.question.command.domain.QQuestion.question; + import com.developer.wiki.question.command.domain.MainCategory; import com.developer.wiki.question.command.domain.Question; import com.developer.wiki.question.command.domain.QuestionSearchRepository; @@ -9,18 +12,18 @@ import com.querydsl.core.BooleanBuilder; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; -import org.springframework.data.domain.*; -import org.springframework.stereotype.Repository; -import org.springframework.util.ObjectUtils; - -import javax.persistence.EntityManager; import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; - -import static com.developer.wiki.bookmark.QBookmark.bookmark; -import static com.developer.wiki.question.command.domain.QQuestion.question; +import javax.persistence.EntityManager; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.domain.SliceImpl; +import org.springframework.stereotype.Repository; +import org.springframework.util.ObjectUtils; @Repository public class QuestionSearchRepositoryImpl implements QuestionSearchRepository { @@ -38,16 +41,14 @@ public Page findPageByUserId(Pageable pageable, String .leftJoin(question.bookmarks) .where(mainCategoryEq(mainCategory), subCategoryEq(mainCategory, subCategory), question.isApproved.isTrue()).orderBy(question.id.asc()).offset(pageable.getOffset()) - .limit(pageable.getPageSize() + 1).distinct().fetch(); + .limit(pageable.getPageSize()).distinct().fetch(); List summaryQuestionResponses = questions.stream().map(question -> { Boolean isBookmarked = exist(question.getId(), userId); return new SummaryQuestionResponse(question.getId(), question.getTitle(), question.getMainCategory(), question.getSubCategory(), question.getViewCount(), question.getCommentCount(), question.getCreatedAt(), isBookmarked); }).collect(Collectors.toList()); - System.out.println(summaryQuestionResponses); - Long count = jpaQueryFactory.select(question.count()).from(question).fetchOne(); - return new PageImpl<>(summaryQuestionResponses, pageable, count); + return new PageImpl<>(summaryQuestionResponses, pageable, questions.size()); } @Override @@ -65,9 +66,7 @@ public Page findBookmarkByUserId(Pageable pageable, Str question.getMainCategory(), question.getSubCategory(), question.getViewCount(), question.getCommentCount(), question.getCreatedAt(), isBookmarked); }).collect(Collectors.toList()); - System.out.println(summaryQuestionResponses); - Long count = jpaQueryFactory.select(question.count()).from(question).fetchOne(); - return new PageImpl<>(summaryQuestionResponses, pageable, count); + return new PageImpl<>(summaryQuestionResponses, pageable, questions.size()); } @Override