diff --git a/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java b/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java index 9b5d3c3..09ab838 100644 --- a/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java +++ b/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java @@ -34,10 +34,12 @@ public List giveStoreInRange(@RequestParam BigDecimal latStart @RequestParam BigDecimal latEnd, @RequestParam BigDecimal lngStart, @RequestParam BigDecimal lngEnd, + @RequestParam(required = false) String category, + @RequestParam(required = false) List facility, // sort 기준 정하기 //@PageableDefault(sort = {""}, direction = Sort.Direction.DESC) Pageable pageable){ @PageableDefault Pageable pageable) { - List betweenLngLat = storeQueryRepository.findBetweenLngLat(latStart, latEnd, lngStart, lngEnd, pageable); - return betweenLngLat.stream().map(storeService::storeToResDto).collect(Collectors.toList()); + List betweenLngLat = storeQueryRepository.findBetweenLngLat(latStart, latEnd, lngStart, lngEnd, category, facility, pageable); + return betweenLngLat.parallelStream().map(storeService::storeToResDto).collect(Collectors.toList());// 순서보장 } } diff --git a/src/main/java/com/mpnp/baechelin/store/controller/StoreQueryRepository.java b/src/main/java/com/mpnp/baechelin/store/controller/StoreQueryRepository.java index f342f46..614437b 100644 --- a/src/main/java/com/mpnp/baechelin/store/controller/StoreQueryRepository.java +++ b/src/main/java/com/mpnp/baechelin/store/controller/StoreQueryRepository.java @@ -1,6 +1,14 @@ package com.mpnp.baechelin.store.controller; +import com.mpnp.baechelin.store.domain.QStore; import com.mpnp.baechelin.store.domain.Store; +import com.mpnp.baechelin.tag.domain.QTag; +import com.querydsl.core.BooleanBuilder; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.CaseBuilder; +import com.querydsl.core.types.dsl.Expressions; +import com.querydsl.core.types.dsl.StringPath; +import com.querydsl.jpa.JPAExpressions; import com.querydsl.jpa.impl.JPAQueryFactory; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport; @@ -9,6 +17,7 @@ import javax.transaction.Transactional; import java.math.BigDecimal; import java.util.List; +import java.util.Objects; import static com.mpnp.baechelin.store.domain.QStore.store; @@ -17,24 +26,66 @@ public class StoreQueryRepository extends QuerydslRepositorySupport { private final JPAQueryFactory queryFactory; - public StoreQueryRepository(JPAQueryFactory queryFactory) { + public StoreQueryRepository(JPAQueryFactory queryFactory) { super(Store.class); this.queryFactory = queryFactory; } + // TODO 카테고리, 시설 추가하기 public List findBetweenLngLat(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, + String category, + List facility, Pageable pageable) { + + BooleanBuilder builder = new BooleanBuilder(); + builder.and(store.latitude.goe(latStart)); + builder.and(store.latitude.loe(latEnd)); + builder.and(store.longitude.goe(lngStart)); + builder.and(store.longitude.loe(lngEnd)); + builder.and(category == null ? null : store.category.eq(category)); + if (facility != null && facility.size() > 0) { + for (String fac : facility) { + builder.and(facilityTF(fac)); + } + } + List storeList = queryFactory.selectFrom(store) - .where(store.latitude.goe(latStart), - store.latitude.loe(latEnd), - store.longitude.goe(lngStart), - store.longitude.loe(lngEnd)) + .where(builder) .limit(pageable.getPageSize()) .offset(pageable.getOffset()) .fetch(); + return storeList; } + + private BooleanExpression facilityTF(String facility) { + if (facility == null || facility.isEmpty()) return null; + return givePath(facility).eq("Y"); + } + + private StringPath givePath(String dbFacility) { + if (dbFacility.equals("elevator")) + return store.elevator; + if (dbFacility.equals("heightDifferent")) + return store.heightDifferent; + if (dbFacility.equals("parking")) + return store.parking; + if (dbFacility.equals("approach")) + return store.approach; + else + return store.toilet; + } + + + + //TODO 주변밥집 + + //TODO 별점순 + + //TODO 실시간 맛집 + + //TODO 북마크순 } diff --git a/src/main/java/com/mpnp/baechelin/api/model/Category.java b/src/main/java/com/mpnp/baechelin/store/domain/Category.java similarity index 92% rename from src/main/java/com/mpnp/baechelin/api/model/Category.java rename to src/main/java/com/mpnp/baechelin/store/domain/Category.java index cc84930..7366597 100644 --- a/src/main/java/com/mpnp/baechelin/api/model/Category.java +++ b/src/main/java/com/mpnp/baechelin/store/domain/Category.java @@ -1,4 +1,4 @@ -package com.mpnp.baechelin.api.model; +package com.mpnp.baechelin.store.domain; import java.util.Arrays; diff --git a/src/main/java/com/mpnp/baechelin/store/domain/Facility.java b/src/main/java/com/mpnp/baechelin/store/domain/Facility.java new file mode 100644 index 0000000..048730c --- /dev/null +++ b/src/main/java/com/mpnp/baechelin/store/domain/Facility.java @@ -0,0 +1,4 @@ +package com.mpnp.baechelin.store.domain; + +public enum Facility { +}