Skip to content

Commit

Permalink
#16 [Fix] 두 기능을 한번에 가지는 Controller , Repository 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoi committed Jul 27, 2022
1 parent 0542219 commit f54fb2f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,26 @@ public class StoreController {

@ApiOperation(value = "조건에 맞는 업장 목록을 반환하는 메소드")
@GetMapping("/near")
// public List<StoreCardResponseDto> getStoreInRange(@RequestParam(required = false) BigDecimal latStart,
public StorePagedResponseDto getStoreInRange(@RequestParam(required = false) BigDecimal lat,
@RequestParam(required = false) BigDecimal lng,
@RequestParam(required = false) String category,
@RequestParam(required = false) List<String> facility,
@PageableDefault Pageable pageable,
@AuthenticationPrincipal User user) {
return storeService.getStoreInOnePointRange(lat, lng, category, facility, pageable, user == null ? null : user.getUsername());
}

@ApiOperation(value = "지도에서 조건에 맞는 업장 목록을 반환하는 메소드")
@GetMapping("/near-map")
public StorePagedResponseDto getStoreInRange(@RequestParam(required = false) BigDecimal latStart,
@RequestParam(required = false) BigDecimal latEnd,
@RequestParam(required = false) BigDecimal lngStart,
@RequestParam(required = false) BigDecimal lngEnd,
@RequestParam(required = false) BigDecimal lat,
@RequestParam(required = false) BigDecimal lng,
@RequestParam(required = false) String category,
@RequestParam(required = false) List<String> facility,
@PageableDefault Pageable pageable,
@AuthenticationPrincipal User user) {
if (lat != null && lng != null)
return storeService.getStoreInRangeMain(lat, lng, category, facility, pageable, user == null ? null : user.getUsername());
else
return storeService.getStoreInRange(latStart, latEnd, lngStart, lngEnd, category, facility, pageable, user == null ? null : user.getUsername());
return storeService.getStoreInTwoPointsRange(latStart, latEnd, lngStart, lngEnd, category, facility, pageable, user == null ? null : user.getUsername());
}

@GetMapping("/point")
Expand All @@ -63,11 +68,11 @@ public StorePagedResponseDto getStoreInRangeHighPoint(@RequestParam(required = f

@GetMapping("/bookmark")
public StorePagedResponseDto getStoreInRangeHighBookmark(@RequestParam(required = false) BigDecimal lat,
@RequestParam(required = false) BigDecimal lng,
@RequestParam(required = false) String category,
@RequestParam(required = false) List<String> facility,
@PageableDefault Pageable pageable,
@AuthenticationPrincipal User user) {
@RequestParam(required = false) BigDecimal lng,
@RequestParam(required = false) String category,
@RequestParam(required = false) List<String> facility,
@PageableDefault Pageable pageable,
@AuthenticationPrincipal User user) {
return storeService.getStoreInRangeHighBookmark(lat, lng, category, facility, pageable, user == null ? null : user.getUsername());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public StoreQueryRepository(JPAQueryFactory queryFactory) {
this.queryFactory = queryFactory;
}

public Page<Store> findBetweenLngLat(BigDecimal latStart,
BigDecimal latEnd,
BigDecimal lngStart,
BigDecimal lngEnd,
String category,
List<String> facility,
Pageable pageable) {
public Page<Store> findBetweenOnePointOrder(BigDecimal latStart,
BigDecimal latEnd,
BigDecimal lngStart,
BigDecimal lngEnd,
String category,
List<String> facility,
Pageable pageable) {
BigDecimal nowLat = (latStart.add(latEnd)).divide(new BigDecimal("2"), 22, RoundingMode.HALF_UP);
BigDecimal nowLng = (lngStart.add(lngEnd)).divide(new BigDecimal("2"), 22, RoundingMode.HALF_UP);
BooleanBuilder builder = QuerydslLocation.locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility);
Expand All @@ -62,6 +62,25 @@ public Page<Store> findBetweenLngLat(BigDecimal latStart,
return new PageImpl<>(storeList, pageable, fetchCount);
}

public Page<Store> findBetweenTwoPoint(BigDecimal latStart,
BigDecimal latEnd,
BigDecimal lngStart,
BigDecimal lngEnd,
String category,
List<String> facility,
Pageable pageable) {
BooleanBuilder builder = QuerydslLocation.locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility);
List<Store> storeList =
queryFactory
.selectFrom(store)
.where(builder)
.limit(pageable.getPageSize())
.offset(pageable.getOffset())
.fetch();
int fetchCount = queryFactory.selectFrom(store).where(builder).fetch().size();
return new PageImpl<>(storeList, pageable, fetchCount);
}

//TODO 별점순 - 쿼리 결과로 산출된 리스트의 평균 구하기, 정렬, 페이징
public Page<Store> findStoreOrderByPoint(BigDecimal lat,
BigDecimal lng,
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/com/mpnp/baechelin/store/service/StoreService.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,19 @@ public class StoreService {
public StorePagedResponseDto getStoreInRange(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, String category, List<String> facility, Pageable pageable, String socialId) {
// public List<StoreCardResponseDto> getStoreInRange(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, String category, List<String> facility, Pageable pageable, String socialId) {
User targetUser = socialId == null ? null : userRepository.findBySocialId(socialId);
Page<Store> betweenLngLat = storeQueryRepository.findBetweenLngLat(latStart, latEnd, lngStart, lngEnd, category, facility, pageable);
Page<Store> betweenLngLat = storeQueryRepository.findBetweenOnePointOrder(latStart, latEnd, lngStart, lngEnd, category, facility, pageable);
// store 가져와서 dto 매핑
return getStoreCardPagedResponseDto(targetUser, betweenLngLat);
}

public StorePagedResponseDto getStoreInTwoPointsRange(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, String category, List<String> facility, Pageable pageable, String socialId) {
// public List<StoreCardResponseDto> getStoreInRange(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, String category, List<String> facility, Pageable pageable, String socialId) {
User targetUser = socialId == null ? null : userRepository.findBySocialId(socialId);
Page<Store> betweenSquare = storeQueryRepository.findBetweenTwoPoint(latStart, latEnd, lngStart, lngEnd, category, facility, pageable);
// store 가져와서 dto 매핑
return getStoreCardPagedResponseDto(targetUser, betweenSquare);
}

/**
* @param lat 위도
* @param lng 경도
Expand All @@ -67,7 +75,7 @@ public StorePagedResponseDto getStoreInRange(BigDecimal latStart, BigDecimal lat
* @param socialId 유저 소셜 로그인 아이디
* @return 위도, 경도, 카테고리, 배리어 프리, 페이징을 만족하는 배리어 프리 업장 리턴
*/
public StorePagedResponseDto getStoreInRangeMain(BigDecimal lat, BigDecimal lng, String category, List<String> facility, Pageable pageable, String socialId) {
public StorePagedResponseDto getStoreInOnePointRange(BigDecimal lat, BigDecimal lng, String category, List<String> facility, Pageable pageable, String socialId) {
BigDecimal[] range = QuerydslLocation.getRange(lat, lng, 10);
return getStoreInRange(range[0], range[1], range[2], range[3], category, facility, pageable, socialId);
}
Expand Down Expand Up @@ -160,7 +168,8 @@ private List<StoreCardResponseDto> getStoreCardResponseDtos(User targetUser, Lis

/**
* 업장 상세 조회
* @param storeId 업장 아이디
*
* @param storeId 업장 아이디
* @param socialId 유저 social 아이디
* @return 업장 상세 정보
*/
Expand Down Expand Up @@ -196,6 +205,7 @@ public StoreDetailResponseDto getStore(long storeId, String socialId) {

/**
* 시/도 (ex. 서울시, 대전광역시)의 시/군/구 리스트 조회
*
* @param sido 시/도
* @return 시/군/구 리스트
*/
Expand All @@ -221,9 +231,10 @@ public Map<String, List<String>> getSigungu(String sido) {

/**
* 업장 검색
* @param sido 시/도명
* @param sigungu 시/군/구명
* @param keyword 검색어
*
* @param sido 시/도명
* @param sigungu 시/군/구명
* @param keyword 검색어
* @param socialId 업장 pk
* @param pageable page, size
* @return
Expand Down

0 comments on commit f54fb2f

Please sign in to comment.