Skip to content

Commit

Permalink
#18 [Refactor] BooleanBuilder 리팩터링, DTO Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoi committed Jul 13, 2022
1 parent 519a1c0 commit d2abd7f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
4 changes: 3 additions & 1 deletion src/main/java/com/mpnp/baechelin/config/QuerydslConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(entityManager);
}

public static void locationBuilder(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, BooleanBuilder builder) {
public static BooleanBuilder locationBuilder(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd) {
BooleanBuilder builder = new BooleanBuilder();
builder.and(latStart == null ? null : store.latitude.goe(latStart));
builder.and(latEnd == null ? null : store.latitude.loe(latEnd));
builder.and(lngStart == null ? null : store.longitude.goe(lngStart));
builder.and(lngEnd == null ? null : store.longitude.loe(lngEnd));
return builder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
@Transactional
public class ReviewQueryRepository extends QuerydslRepositorySupport {
private final JPAQueryFactory queryFactory;
private final BooleanBuilder builder = new BooleanBuilder();

public ReviewQueryRepository(JPAQueryFactory queryFactory) {
super(Review.class);
Expand All @@ -30,12 +29,13 @@ public List<Review> findRecentReviews(BigDecimal latStart,
BigDecimal lngStart,
BigDecimal lngEnd,
int limit) {
locationBuilder(latStart, latEnd, lngStart, lngEnd, builder);
BooleanBuilder builder = locationBuilder(latStart, latEnd, lngStart, lngEnd);
// 위도 경도에 해당하는 가게를 찾음 -> 해당 댓글을 다 가져옴 -> 내림차순 정렬 -> limit
return queryFactory.selectFrom(review1)
.innerJoin(review1.storeId, store)
.on(review1.storeId.id.eq(store.id))
.where(builder)
.orderBy(review1.createdAt.desc())
.limit(limit)
.fetch();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import java.math.BigDecimal;
import java.util.List;

import static com.mpnp.baechelin.config.QuerydslConfig.locationBuilder;
import static com.mpnp.baechelin.store.domain.QStore.store;

@Repository
@Transactional
public class StoreQueryRepository extends QuerydslRepositorySupport {
private final JPAQueryFactory queryFactory;
private final BooleanBuilder builder = new BooleanBuilder();

public StoreQueryRepository(JPAQueryFactory queryFactory) {
super(Store.class);
Expand All @@ -36,7 +36,7 @@ public List<Store> findBetweenLngLat(BigDecimal latStart,
List<String> facility,
Pageable pageable) {

locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility);
BooleanBuilder builder = locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility);

return queryFactory.selectFrom(store)
.where(builder)
Expand All @@ -55,23 +55,14 @@ public List<Store> findStoreOrderByPoint(BigDecimal latStart,
Pageable pageable) {


locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility);
BooleanBuilder builder = locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility);

return queryFactory.selectFrom(store)
.where(builder)
.orderBy(store.pointAvg.desc())
.limit(pageable.getPageSize())
.offset(pageable.getOffset())
.orderBy(store.pointAvg.desc())
.fetch();

// return queryFactory.selectFrom(store)
// .leftJoin(store, review1.storeId)
// .on(store.id.eq(review1.storeId.id))
// .where(builder)
// .orderBy(review1.point.avg().desc())
// .limit(pageable.getPageSize())
// .offset(pageable.getOffset())
// .fetch();
}

//TODO 북마크순
Expand All @@ -83,7 +74,8 @@ public List<Store> findStoreOrderByBookmark(BigDecimal latStart,
List<String> facility,
int limit) {

locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility);
BooleanBuilder builder = locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility);


return queryFactory.selectFrom(store)
.where(builder)
Expand Down Expand Up @@ -111,13 +103,14 @@ private StringPath givePath(String dbFacility) {
return store.toilet;
}

private void locAndConditions(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, String category, List<String> facility) {
QuerydslConfig.locationBuilder(latStart, latEnd, lngStart, lngEnd, builder);
private BooleanBuilder locAndConditions(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, String category, List<String> facility) {
BooleanBuilder builder = locationBuilder(latStart, latEnd, lngStart, lngEnd);
builder.and(category == null ? null : store.category.eq(category));
if (facility != null && facility.size() > 0) {
for (String fac : facility) {
builder.and(facilityTF(fac));
}
}
return builder;
}
}

0 comments on commit d2abd7f

Please sign in to comment.