Skip to content

Commit

Permalink
Merge pull request #110 from Developer-Wikis/feature/#108
Browse files Browse the repository at this point in the history
fix: 목록 조회 수정
  • Loading branch information
dhkstnaos authored Dec 1, 2022
2 parents bd00e9d + d5303fb commit 0390a8b
Showing 1 changed file with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -38,16 +41,14 @@ public Page<SummaryQuestionResponse> 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<SummaryQuestionResponse> 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
Expand All @@ -65,9 +66,7 @@ public Page<SummaryQuestionResponse> 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
Expand Down

0 comments on commit 0390a8b

Please sign in to comment.