Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import dev.book.challenge.dto.response.ChallengeReadResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.support.PageableExecutionUtils;
import org.springframework.stereotype.Repository;

import java.util.List;
Expand Down Expand Up @@ -37,12 +38,11 @@ public Page<ChallengeReadResponse> search(String title, String text, Pageable pa
.limit(pageable.getPageSize())
.fetch();

long totalCount = jpaQueryFactory.select(challenge.count())
JPAQuery<Long> countQuery = jpaQueryFactory.select(challenge.count())
.from(challenge)
.where(eqTitle(title),
eqText(text))
.fetchOne();
return new PageImpl<>(content, pageable, totalCount);
eqText(text));
return PageableExecutionUtils.getPage(content, pageable, countQuery::fetchOne);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ public interface UserChallengeRepository extends JpaRepository<UserChallenge, Lo

@Query("""
SELECT uc FROM UserChallenge uc
JOIN FETCH uc.challenge c
JOIN FETCH c.challengeCategories cc
JOIN FETCH cc.category ca
WHERE uc.user.id=:id
""")
List<UserChallenge> findChallengeByUserId(Long id, Pageable pageable);
Expand Down