Skip to content

Commit

Permalink
feat(store): 좌표 내 케이크샵 조회 api 구현 #31
Browse files Browse the repository at this point in the history
  • Loading branch information
govl6113 committed Jun 22, 2023
1 parent 4c3fffe commit de1c59c
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ public ResponseEntity<List<StoreResponse>> getList(
return ResponseEntity.ok().body(this.storeUseCase.getList(district, page));
}

@Operation(description = "이 지역 재검색")
@GetMapping("/reload")
public ResponseEntity<List<StoreResponse>> reload(
@RequestParam(value = "page", required = false, defaultValue = "1") int page,
@RequestParam(value = "southwestLatitude", required = true) Double southwestLatitude,
@RequestParam(value = "southwestLongitude", required = true) Double southwestLongitude,
@RequestParam(value = "northeastLatitude", required = true) Double northeastLatitude,
@RequestParam(value = "northeastLongitude", required = true) Double northeastLongitude
) {
return ResponseEntity.ok().body(
this.storeUseCase.reload(
page,
southwestLatitude, southwestLongitude,
northeastLatitude, northeastLongitude
)
);
}

@Operation(description = "케이크샵 상세 정보 조회(상세 정보만)")
@GetMapping("/{id}")
public ResponseEntity<StoreDetailResponse> getStoreDetail(@PathVariable("id") Long storeId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.stereotype.Repository;

import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -46,13 +47,19 @@ public List<DistrictCountResponse> getDistrictCount() {
}

@Override
public List<StoreResponse> getList(List<District> district, Pageable pageable) {
public List<StoreResponse> getList(
List<District> district, Pageable pageable,
Double southwestLatitude, Double southwestLongitude,
Double northeastLatitude, Double northeastLongitude
) {
return queryFactory
.selectFrom(store)
.leftJoin(store.storeAndTagList, storeAndTag)
.leftJoin(storeAndTag.storeTag, storeTag)
.where(
store.district.in(district)
storeDistrictIn(district),
storeLongitudeBetween(southwestLongitude, northeastLongitude),
storeLatitudeBetween(southwestLatitude, northeastLatitude)
)
.distinct()
.offset(pageable.getOffset())
Expand Down Expand Up @@ -89,4 +96,18 @@ public Map<Long, StoreResponse> getStoreDetail(Long storeId) {
public Optional<Store> getByName(String name) {
return storeRepository.findByName(name);
}
}

private BooleanExpression storeDistrictIn(List<District> district) {
return district != null ? store.district.in(district) : null;
}

private BooleanExpression storeLongitudeBetween(Double southwestLongitude, Double northeastLongitude) {
return southwestLongitude != null || northeastLongitude != null ?
store.longitude.between(southwestLongitude, northeastLongitude) : null;
}

private BooleanExpression storeLatitudeBetween(Double southwestLatitude, Double northeastLatitude) {
return southwestLatitude != null || northeastLatitude != null ?
store.latitude.between(southwestLatitude, northeastLatitude) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ public interface StoreUseCase {

List<StoreResponse> getList(List<District> district, int page);

List<StoreResponse> reload(
int page,
Double southwestLatitude, Double southwestLongitude,
Double northeastLatitude, Double northeastLongitude
);

StoreDetailResponse getStoreDetail(Long storeId);

StoreBlogResponse getStoreBlog(Long storeId, Integer blogNum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
public interface LoadStorePort {
List<DistrictCountResponse> getDistrictCount();

List<StoreResponse> getList(List<District> district, Pageable pageable);
List<StoreResponse> getList(
List<District> district, Pageable pageable,
Double southwestLongitude, Double northeastLongitude,
Double southwestLatitude, Double northeastLatitude
);

Map<Long, StoreResponse> getStoreDetail(Long storeId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,29 @@ public List<DistrictCountResponse> getCount() {
*/
@Override
public List<StoreResponse> getList(List<District> district, int page) {
return loadStorePort.getList(district, PageRequest.of(page - 1, 15));
return loadStorePort.getList(district, PageRequest.of(page - 1, 100), null, null, null, null);
}

/**
* 현재 화면의 남서쪽 위도, 경도, 북동쪽 위도, 경도를 받아 해당하는 가게 리스트를 반환합니다.
* @param page 페이지 번호
* @param southwestLatitude 남서쪽 위도
* @param southwestLongitude 남서쪽 경도
* @param northeastLatitude 북동쪽 위도
* @param northeastLongitude 북동쪽 경도
* @return 가게 리스트
*/
@Override
public List<StoreResponse> reload(
int page,
Double southwestLatitude, Double southwestLongitude,
Double northeastLatitude, Double northeastLongitude
) {
return loadStorePort.getList(
null, PageRequest.of(page - 1, 100),
southwestLatitude, southwestLongitude,
northeastLatitude, northeastLongitude
);
}

/**
Expand Down

0 comments on commit de1c59c

Please sign in to comment.