feat(store): 매장 검색 API 즐겨찾기 회수 추가

- 거리순으로 가까운 매장 조회 후 즐겨찾기 회수 검색
This commit is contained in:
bum12ark
2022-03-04 18:04:55 +09:00
parent 624c02905d
commit df352a86a0
4 changed files with 48 additions and 2 deletions

View File

@@ -0,0 +1,22 @@
package com.justpickup.storeservice.domain.favoritestore.repository;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import static com.justpickup.storeservice.domain.favoritestore.entity.QFavoriteStore.favoriteStore;
@Repository
@RequiredArgsConstructor
public class FavoriteStoreCustom {
private final JPAQueryFactory queryFactory;
public Long countFavoriteStoreByStoreId(Long storeId) {
return queryFactory.select(favoriteStore.count())
.from(favoriteStore)
.join(favoriteStore.store)
.where(favoriteStore.store.id.eq(storeId))
.fetchOne();
}
}

View File

@@ -10,6 +10,17 @@ public class SearchStoreResult {
private Long storeId;
private String storeName;
private Double distanceMeter;
private Long favoriteCounts;
public SearchStoreResult(Long storeId, String storeName, Double distanceMeter) {
this.storeId = storeId;
this.storeName = storeName;
this.distanceMeter = distanceMeter;
}
public void setFavoriteCounts(Long favoriteCounts) {
this.favoriteCounts = favoriteCounts;
}
public String convertDistanceToString() {
// km 으로 표시
@@ -23,4 +34,5 @@ public class SearchStoreResult {
// ex) 621m
return new DecimalFormat("0").format(distanceMeter) + "m";
}
}

View File

@@ -1,5 +1,6 @@
package com.justpickup.storeservice.domain.store.service;
import com.justpickup.storeservice.domain.favoritestore.repository.FavoriteStoreCustom;
import com.justpickup.storeservice.domain.store.dto.SearchStoreCondition;
import com.justpickup.storeservice.domain.store.dto.SearchStoreResult;
import com.justpickup.storeservice.domain.store.repository.StoreRepositoryCustom;
@@ -13,9 +14,18 @@ import org.springframework.stereotype.Service;
public class StoreServiceImpl implements StoreService {
private final StoreRepositoryCustom storeRepositoryCustom;
private final FavoriteStoreCustom favoriteStoreCustom;
@Override
public SliceImpl<SearchStoreResult> findSearchStoreScroll(SearchStoreCondition condition, Pageable pageable) {
return storeRepositoryCustom.findSearchStoreScroll(condition, pageable);
SliceImpl<SearchStoreResult> searchStoreScroll =
storeRepositoryCustom.findSearchStoreScroll(condition, pageable);
searchStoreScroll.forEach(result -> {
Long favoriteCounts = favoriteStoreCustom.countFavoriteStoreByStoreId(result.getStoreId());
result.setFavoriteCounts(favoriteCounts);
});
return searchStoreScroll;
}
}

View File

@@ -48,13 +48,15 @@ public class StoreController {
private Long id;
private String name;
private String distance;
private Long favoriteCounts;
}
public SearchStoreResponse(List<SearchStoreResult> content, boolean hasNext) {
this.stores = content.stream()
.map(result ->
new StoreDto(
result.getStoreId(), result.getStoreName(), result.convertDistanceToString())
result.getStoreId(), result.getStoreName(),
result.convertDistanceToString(), result.getFavoriteCounts())
)
.collect(Collectors.toList());
this.hasNext = hasNext;