Skip to content

Commit

Permalink
[ feat ] Apply filter with location and category
Browse files Browse the repository at this point in the history
  • Loading branch information
Minuooooo committed Aug 22, 2023
1 parent 1618f71 commit 7477a0f
Show file tree
Hide file tree
Showing 4 changed files with 347 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,25 @@ public class StoreController {
@Operation(summary = "Get simple store infos API", description = "put keyword if you want to search and page info what you want to see.")
@ResponseStatus(OK)
@GetMapping("/simple")
public Response getSimpleStoreInfos(@RequestParam(required = false) String keyword, @ParameterObject Pageable pageable) {
return success(SUCCESS_TO_GET_SIMPLE_STORE_INFOS, storeService.getSimpleStoreInfos(keyword, pageable));
public Response getSimpleStoreInfos(
@RequestParam(required = false) String keyword,
@RequestParam(required = false) String location,
@RequestParam(required = false) String category,
@ParameterObject Pageable pageable
) {
return success(SUCCESS_TO_GET_SIMPLE_STORE_INFOS, storeService.getSimpleStoreInfos(keyword, location, category, pageable));
}

// 인증된 사용자의 스토어 목록 불러오기 API (new, best, all, search, sort by bookmarks & reviews)
@Operation(summary = "Get simple store infos with auth member API", description = "put keyword if you want to search and page info what you want to see.")
@ResponseStatus(OK)
@GetMapping("/auth/simple")
public Response getSimpleStoreInfosWithAuthMember(@RequestParam(required = false) String keyword, @ParameterObject Pageable pageable) {
public Response getSimpleStoreInfosWithAuthMember(
@RequestParam(required = false) String keyword,
@RequestParam(required = false) String location,
@RequestParam(required = false) String category,
@ParameterObject Pageable pageable
) {
return success(
SUCCESS_TO_GET_SIMPLE_STORE_INFOS,
storeService.getSimpleStoreInfoWithAuthMember(
Expand All @@ -57,4 +67,4 @@ public Response getSimpleStoreInfosWithAuthMember(@RequestParam(required = false
public Response getStoreInfo(Long storeId) {
return success(SUCCESS_TO_GET_STORE_INFO, storeService.getStoreInfo(storeId));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@

public interface StoreRepository extends JpaRepository<Store, Long> {
Page<Store> findStoresByNameContainingIgnoreCase(String keyword, Pageable pageable); // 검색어를 포함하는 이름을 가진 스토어 목록 가져오기
Page<Store> findStoresByLocationContainingIgnoreCase(String location, Pageable pageable);
Page<Store> findStoresByCategoryContainingIgnoreCase(String category, Pageable pageable);
Page<Store> findStoresByNameContainingIgnoreCaseAndLocationContainingIgnoreCase(String keyword, String location, Pageable pageable);
Page<Store> findStoresByNameContainingIgnoreCaseAndCategoryContainingIgnoreCase(String keyword, String category, Pageable pageable);
Page<Store> findStoresByLocationContainingIgnoreCaseAndCategoryContainingIgnoreCase(String location, String category, Pageable pageable);
Page<Store> findStoresByNameContainingIgnoreCaseAndLocationContainingIgnoreCaseAndCategoryContainingIgnoreCase(String keyword, String location, String category, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,44 @@ public class StoreService {

private final StoreRepository storeRepository;

public Page<GetSimpleStoreInfosResponseDto> getSimpleStoreInfos(String keyword, Pageable pageable) { // 모든 사용자에 대한 스토어 목록 조회
public Page<GetSimpleStoreInfosResponseDto> getSimpleStoreInfos(String keyword, String location, String category, Pageable pageable) { // 모든 사용자에 대한 스토어 목록 조회

if (StringUtils.hasText(keyword)) { // 키워드가 존재할 경우
return storeRepository.findStoresByNameContainingIgnoreCase(keyword, pageable)
if (StringUtils.hasText(keyword) && !StringUtils.hasText(location) && !StringUtils.hasText(category)) {
return getStoresWithKeyword(keyword, pageable)
.map(store -> GetSimpleStoreInfosResponseDto.from(store, false));
}

return storeRepository.findAll(pageable)
if(!StringUtils.hasText(keyword) && StringUtils.hasText(location) && !StringUtils.hasText(category)) {
return getStoresWithLocation(location, pageable)
.map(store -> GetSimpleStoreInfosResponseDto.from(store, false));
}

if(!StringUtils.hasText(keyword) && !StringUtils.hasText(location) && StringUtils.hasText(category)) {
return getStoresWithCategory(category, pageable)
.map(store -> GetSimpleStoreInfosResponseDto.from(store, false));
}

if(StringUtils.hasText(keyword) && StringUtils.hasText(location) && !StringUtils.hasText(category)) {
return getStoresWithKeywordAndLocation(keyword, location, pageable)
.map(store -> GetSimpleStoreInfosResponseDto.from(store, false));
}

if(StringUtils.hasText(keyword) && !StringUtils.hasText(location) && StringUtils.hasText(category)) {
return getStoresWithKeywordAndCategory(keyword, category, pageable)
.map(store -> GetSimpleStoreInfosResponseDto.from(store, false));
}

if(!StringUtils.hasText(keyword) && StringUtils.hasText(location) && StringUtils.hasText(category)) {
return getStoresWithLocationAndCategory(location, category, pageable)
.map(store -> GetSimpleStoreInfosResponseDto.from(store, false));
}

if(StringUtils.hasText(keyword) && StringUtils.hasText(location) && StringUtils.hasText(category)) {
return getStoresWithKeywordAndLocationAndCategory(keyword, location, category, pageable)
.map(store -> GetSimpleStoreInfosResponseDto.from(store, false));
}

return getStores(pageable)
.map(store -> GetSimpleStoreInfosResponseDto.from(store, false));
}

Expand All @@ -59,6 +89,38 @@ public Store getStore(Long storeId) { // Id 값을 통해 Store 객체 가져
.orElseThrow(StoreNotFoundException::new);
}

private Page<Store> getStoresWithKeyword(String keyword, Pageable pageable) {
return storeRepository.findStoresByNameContainingIgnoreCase(keyword, pageable);
}

private Page<Store> getStoresWithLocation(String location, Pageable pageable) {
return storeRepository.findStoresByLocationContainingIgnoreCase(location, pageable);
}

private Page<Store> getStoresWithCategory(String category, Pageable pageable) {
return storeRepository.findStoresByCategoryContainingIgnoreCase(category, pageable);
}

private Page<Store> getStoresWithKeywordAndLocation(String keyword, String location, Pageable pageable) {
return storeRepository.findStoresByNameContainingIgnoreCaseAndLocationContainingIgnoreCase(keyword, location, pageable);
}

private Page<Store> getStoresWithKeywordAndCategory(String keyword, String category, Pageable pageable) {
return storeRepository.findStoresByNameContainingIgnoreCaseAndCategoryContainingIgnoreCase(keyword, category, pageable);
}

private Page<Store> getStoresWithLocationAndCategory(String location, String category, Pageable pageable) {
return storeRepository.findStoresByLocationContainingIgnoreCaseAndCategoryContainingIgnoreCase(location, category, pageable);
}

private Page<Store> getStoresWithKeywordAndLocationAndCategory(String keyword, String location, String category, Pageable pageable) {
return storeRepository.findStoresByNameContainingIgnoreCaseAndLocationContainingIgnoreCaseAndCategoryContainingIgnoreCase(keyword, location, category, pageable);
}

private Page<Store> getStores(Pageable pageable) {
return storeRepository.findAll(pageable);
}

// 페이지네이션으로 불러온 스토어 목록과 인증된 사용자의 찜한 스토어 목록을 비교하여 찜 표시
private Page<GetSimpleStoreInfosResponseDto> checkBookmarkedStore(List<Store> stores, List<StoreBookmark> storeBookmarks, Pageable pageable) {
List<GetSimpleStoreInfosResponseDto> simpleStores = new ArrayList<>();
Expand Down
Loading

0 comments on commit 7477a0f

Please sign in to comment.