작성
·
1.7K
0
@Override
public Page<?> findAllPostWithCategory3(Pageable pageable, List<Tech> techList, Category category, Place place) {
JPAQuery<PostResponseDto> query = queryFactory.
select(new QPostResponseDto(post))
.from(post)
.leftJoin(post.account, account).fetchJoin()
.where(checkCategory(category), checkPlace(place))
.leftJoin(post.techs, techs)
.where(checkTechList(techList))
.offset(pageable.getOffset())
.limit(pageable.getPageSize());
// sorting
for (Sort.Order o : pageable.getSort()) {
PathBuilder pathBuilder = new PathBuilder(post.getType(), post.getMetadata());
query.orderBy(new OrderSpecifier(o.isAscending() ? Order.ASC : Order.DESC,
pathBuilder.get(o.getProperty())));
}
List<PostResponseDto> list = query.fetch();
JPAQuery<Long> countQuery = queryFactory
.select(post.count())
.from(post)
.where(checkTechList(techList));
return PageableExecutionUtils.getPage(list, pageable, countQuery::fetchOne);
}
//동적 관리
/*techList in query where*/
private BooleanExpression checkTechList (List < Tech > techList) {
return techList == null ? null : techs.tech.in(techList);
}
/*category in query where*/
private BooleanExpression checkCategory (Category category){
return category == null ? null : post.category.eq(category);
}
/*place in query where*/
private BooleanExpression checkPlace (Place place){
return place == null ? null : post.place.eq(place);
}
Post를 기준으로 account는 manyToOne이고
지금 문제가 되는것은 Tech입니다. Post와 oneToMany관계인데, 동적쿼리를 tech의 값으로 해야되서 문제가 발생합니다..
페이지네이션을 유지해야하기에, 어떻게 짜야할지 모르겠습니다. 제발 도움이나 힌트 부탁드립니다