Skip to content

Commit

Permalink
#23 [Add] 리스트 조회 - 카테고리, 위/경도, 배리어프리 태그로 필터링
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoi committed Jul 12, 2022
1 parent 3b44760 commit 47e8ef1
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mpnp.baechelin.review.dto.ReviewResDTO;
import com.mpnp.baechelin.review.service.ReviewService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand Down Expand Up @@ -38,4 +39,9 @@ public ReviewResDTO review(@RequestParam double point,
reviewService.review(reviewReqDTO);
return null;
}
// TODO - 최근 등록한 리뷰 보여주기
@GetMapping("/recent-review")
public ReviewResDTO recentReview(){
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.mpnp.baechelin.review.repository;

import com.mpnp.baechelin.review.domain.QReview;
import com.mpnp.baechelin.review.domain.Review;
import com.mpnp.baechelin.store.domain.Store;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.math.BigDecimal;
import java.util.List;

import static com.mpnp.baechelin.review.domain.QReview.review1;
import static com.mpnp.baechelin.store.domain.QStore.store;

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

public ReviewQueryRepository(JPAQueryFactory queryFactory) {
super(Review.class);
this.queryFactory = queryFactory;
}

public List<Review> findRecentReviews(BigDecimal latStart,
BigDecimal latEnd,
BigDecimal lngStart,
BigDecimal lngEnd,
int limit) {
builder.and(store.latitude.goe(latStart));
builder.and(store.latitude.loe(latEnd));
builder.and(store.longitude.goe(lngStart));
builder.and(store.longitude.loe(lngEnd));
// 위도 경도에 해당하는 가게를 찾음 -> 해당 댓글을 다 가져옴 -> 내림차순 정렬 -> limit
return queryFactory.selectFrom(review1)
.innerJoin(review1.storeId, store)
.where(review1.storeId
.in(queryFactory.select(store).from(store).where(builder)))
.limit(limit)
.fetch();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public class StoreController {

@GetMapping
public List<StoreResponseDto> getStoreList() {
List<StoreResponseDto> storeList = storeService.getStoreList();
return storeList;
return storeService.getStoreList();
}

@GetMapping("/near")
Expand All @@ -37,10 +36,31 @@ public List<StoreResponseDto> giveStoreInRange(@RequestParam BigDecimal latStart
@RequestParam BigDecimal lngEnd,
@RequestParam(required = false) String category,
@RequestParam(required = false) List<String> facility,
// sort 기준 정하기
//@PageableDefault(sort = {""}, direction = Sort.Direction.DESC) Pageable pageable){
@PageableDefault Pageable pageable) {
List<Store> betweenLngLat = storeQueryRepository.findBetweenLngLat(latStart, latEnd, lngStart, lngEnd, category, facility, pageable);
return betweenLngLat.parallelStream().map(storeService::storeToResDto).collect(Collectors.toList());// 순서보장
}
@GetMapping("/near/high-point")
public List<StoreResponseDto> giveStoreInRangeHighPoint(@RequestParam BigDecimal latStart,
@RequestParam BigDecimal latEnd,
@RequestParam BigDecimal lngStart,
@RequestParam BigDecimal lngEnd,
@RequestParam(required = false) String category,
@RequestParam(required = false) List<String> facility,
@PageableDefault Pageable pageable) {
List<Store> betweenLngLat = storeQueryRepository.findBetweenLngLat(latStart, latEnd, lngStart, lngEnd, category, facility, pageable);
return betweenLngLat.parallelStream().map(storeService::storeToResDto).collect(Collectors.toList());// 순서보장
}

@GetMapping("/near/high-bookmark")
public List<StoreResponseDto> giveStoreInRangeHighBookmark(@RequestParam BigDecimal latStart,
@RequestParam BigDecimal latEnd,
@RequestParam BigDecimal lngStart,
@RequestParam BigDecimal lngEnd,
@RequestParam(required = false) String category,
@RequestParam(required = false) List<String> facility,
@RequestParam int limit) {
List<Store> betweenLngLat = storeQueryRepository.findStoreOrderByBookmark(latStart, latEnd, lngStart, lngEnd, category, facility, limit);
return betweenLngLat.parallelStream().map(storeService::storeToResDto).collect(Collectors.toList());// 순서보장
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
@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 @@ -40,25 +41,51 @@ public List<Store> findBetweenLngLat(BigDecimal latStart,
List<String> 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));
}
}
locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility);

List<Store> storeList = queryFactory.selectFrom(store)
return queryFactory.selectFrom(store)
.where(builder)
.limit(pageable.getPageSize())
.offset(pageable.getOffset())
.fetch();
}

//TODO 별점순
public List<Store> findStoreOrderByPoint(BigDecimal latStart,
BigDecimal latEnd,
BigDecimal lngStart,
BigDecimal lngEnd,
String category,
List<String> facility,
int limit) {


locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility);

return queryFactory.selectFrom(store)
.where(builder)
.orderBy(store.pointAvg.desc())
.limit(limit)
.fetch();
}

//TODO 북마크순
public List<Store> findStoreOrderByBookmark(BigDecimal latStart,
BigDecimal latEnd,
BigDecimal lngStart,
BigDecimal lngEnd,
String category,
List<String> facility,
int limit) {

locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility);

return queryFactory.selectFrom(store)
.where(builder)
.orderBy(store.bookMarkCount.desc())
.limit(limit)
.fetch();

return storeList;
}

private BooleanExpression facilityTF(String facility) {
Expand All @@ -79,12 +106,16 @@ private StringPath givePath(String dbFacility) {
return store.toilet;
}




//TODO 별점순

//TODO 실시간 맛집

//TODO 북마크순
private void locAndConditions(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, String category, List<String> facility) {
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));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class UserInfoResponseDto {

public UserInfoResponseDto(User user) {
this.name = user.getName();
this.reviewList = user.getReviewsList().stream().map(ReviewResponseDto::new).collect(Collectors.toList());
this.reviewList = user.getReviewList().stream().map(ReviewResponseDto::new).collect(Collectors.toList());
this.bookmarkFolderList = user.getFolderList().stream().map(BookmarkFolderResponseDto::new).collect(Collectors.toList());
//folder

Expand Down

0 comments on commit 47e8ef1

Please sign in to comment.