diff --git a/src/main/java/site/kikihi/custom/global/response/ErrorCode.java b/src/main/java/site/kikihi/custom/global/response/ErrorCode.java index 5984e38..8a6be81 100644 --- a/src/main/java/site/kikihi/custom/global/response/ErrorCode.java +++ b/src/main/java/site/kikihi/custom/global/response/ErrorCode.java @@ -28,8 +28,8 @@ public enum ErrorCode { INVALID_INPUT(400_002, HttpStatus.BAD_REQUEST, "입력값이 올바르지 않습니다."), NULL_VALUE(400_003, HttpStatus.BAD_REQUEST, "Null 값이 들어왔습니다."), TEST_ERROR(400_004, HttpStatus.BAD_REQUEST, "테스트 에러입니다."), - ALREADY_ON(400_005, HttpStatus.BAD_REQUEST, "이미 검색어 저장 기능이 켜져있습니다"), - ALREADY_OFF(400_006, HttpStatus.BAD_REQUEST, "이미 검색어 저장 기능이 꺼져있습니다"), + BAD_PRODUCT_DELETE_CUSTOM(403_004, HttpStatus.FORBIDDEN, "커스텀 내부에 존재하지않는 상품을 삭제할 수 없습니다."), + // ======================== diff --git a/src/main/java/site/kikihi/custom/platform/adapter/in/web/CustomKeyboardController.java b/src/main/java/site/kikihi/custom/platform/adapter/in/web/CustomKeyboardController.java index 10b7e3b..7076aeb 100644 --- a/src/main/java/site/kikihi/custom/platform/adapter/in/web/CustomKeyboardController.java +++ b/src/main/java/site/kikihi/custom/platform/adapter/in/web/CustomKeyboardController.java @@ -1,11 +1,13 @@ package site.kikihi.custom.platform.adapter.in.web; +import org.springframework.data.domain.*; import site.kikihi.custom.global.response.ApiResponse; +import site.kikihi.custom.global.response.ErrorCode; import site.kikihi.custom.global.response.page.PageRequest; import site.kikihi.custom.global.response.page.SliceResponse; import site.kikihi.custom.platform.adapter.in.web.dto.request.custom.CustomCategoryType; import site.kikihi.custom.platform.adapter.in.web.dto.request.custom.CustomKeyboardRequest; -import site.kikihi.custom.platform.adapter.in.web.dto.response.custom.CustomKeyboardLayoutResponse; +import site.kikihi.custom.platform.adapter.in.web.dto.request.custom.CustomKeyboardUpdateRequest; import site.kikihi.custom.platform.adapter.in.web.dto.response.custom.CustomKeyboardDetailResponse; import site.kikihi.custom.platform.adapter.in.web.dto.response.custom.CustomKeyboardListResponse; import site.kikihi.custom.platform.adapter.in.web.dto.response.product.ProductListResponse; @@ -16,10 +18,6 @@ import site.kikihi.custom.security.oauth2.domain.PrincipalDetails; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; -import org.springframework.data.domain.SliceImpl; -import org.springframework.data.domain.Sort; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -96,21 +94,6 @@ public ApiResponse> getMyCustoms( return ApiResponse.ok(SliceResponse.from(dtoSlice)); } - /** - * 키보드 배열 종류 조회 - */ - @GetMapping("/layout") - public ApiResponse> getCustomKeyboardLayout() { - - /// 서비스 - List layouts = service.getKeyboardLayouts(); - - /// DTO - List responses = CustomKeyboardLayoutResponse.from(layouts); - - return ApiResponse.ok(responses); - } - /** * 배열에 맞는 상품 조회 */ @@ -119,6 +102,9 @@ public ApiResponse> getCustomKeyboardProducts @AuthenticationPrincipal PrincipalDetails principalDetails, @RequestParam CustomCategoryType category, @RequestParam CustomKeyboardLayout layout, + @RequestParam(required = false) Integer minPrice, + @RequestParam(required = false) Integer maxPrice, + @RequestParam(required = true, defaultValue = "false") boolean bookmark, PageRequest pageRequest ) { @@ -133,22 +119,60 @@ public ApiResponse> getCustomKeyboardProducts ); /// 서비스 - Slice content = service.getCustomProducts(userId, category.getValue(), layout, pageable); + Slice content; + long counts; + + // 파라미터 여부에 따라 분기 처리 + if (!bookmark && minPrice == null && maxPrice == null) { + /// 카테고리만 있는 경우 + var result = service.getCustomProducts(userId, category.getValue(), layout, pageable); + counts = result.getTotalElements(); + content = result; + + } else if (bookmark && minPrice == null && maxPrice == null) { + /// 카테고리와 북마크만 있는 경우 + var result = service.getProductsByBookmark(userId, category.getValue(), layout, pageable); + counts = result.getTotalElements(); + content = result; + + } else if (!bookmark && minPrice != null && maxPrice != null) { + /// 카테고리와 가격만 있는 경우 + var result = service.getProductsByCategoryIdAndPrice(userId, category.getValue(), layout, minPrice, maxPrice, pageable); + counts = result.getTotalElements(); + content = result; + + } else if (bookmark && minPrice != null && maxPrice != null) { + /// 카테고리,북마크,가격 모두 있는 경우 + var result = service.getProductsByFilterAndBookmark(userId, category.getValue(), layout, minPrice, maxPrice, pageable); + counts = result.getTotalElements(); + content = result; + } else { + throw new IllegalArgumentException(ErrorCode.BAD_REQUEST.getMessage()); + } - /// 개수 조회 - Long counts = service.getCustomProductCounts(category.getValue(), layout); - - /// DTO 변경 - Slice dtoSlice = new SliceImpl<>( - content.getContent(), - content.getPageable(), - content.hasNext() - ); /// 응답 - return ApiResponse.ok(SliceResponse.from(dtoSlice, counts)); + return ApiResponse.ok(SliceResponse.from(content, counts)); } + + /** + * 커스텀 키보드 내부 상품 추가하기 + * @param request 추가 DTO + * @param principalDetails 유저 + */ + public ApiResponse updateCustomKeyboard( + @RequestBody CustomKeyboardUpdateRequest request, + @AuthenticationPrincipal PrincipalDetails principalDetails + ){ + + /// 서비스 + service.insertProductInCustomKeyboard(request.getId(), request.getCategory().getValue(), request.getProductId(), principalDetails.getId()); + + return ApiResponse.updated(); + } + + /** * 커스텀 키보드 삭제 API * @param id 삭제할 커스텀 키보드 @@ -166,4 +190,25 @@ public ApiResponse deleteCustomKeyboard( return ApiResponse.deleted(); } + + /** + * 커스텀 키보드 내부 상품 삭제 API + * @param id 수정할 커스텀 키보드 + * @param category 카테고리 API + * @param productId 상품 ID + * @param principalDetails 유저 + */ + @DeleteMapping() + public ApiResponse deleteProductInsideCustom( + @RequestParam Long id, + @RequestParam CustomCategoryType category, + @RequestParam String productId, + @AuthenticationPrincipal PrincipalDetails principalDetails + ) { + + /// 서비스 호출 + service.deleteCustomInside(id, category.getValue(), productId, principalDetails.getId()); + + return ApiResponse.deleted(); + } } diff --git a/src/main/java/site/kikihi/custom/platform/adapter/in/web/ProductController.java b/src/main/java/site/kikihi/custom/platform/adapter/in/web/ProductController.java index bc74918..74689a8 100644 --- a/src/main/java/site/kikihi/custom/platform/adapter/in/web/ProductController.java +++ b/src/main/java/site/kikihi/custom/platform/adapter/in/web/ProductController.java @@ -60,6 +60,7 @@ public ApiResponse> getProductList(PageReques /// 공통 객체들 저장 Slice products; + Long totalCounts; /// 유저가 없다면 null 저장 UUID userId = principalDetails != null ? principalDetails.getId() : null; @@ -67,27 +68,33 @@ public ApiResponse> getProductList(PageReques // 파라미터 여부에 따라 분기 처리 if (manufacturer == null && minPrice == null && maxPrice == null) { /// 카테고리만 있는 경우 - products = productService.getProductsByCategoryId(userId, category.getValue(), pageable); + var result = productService.getProductsByCategoryId(userId, category.getValue(), pageable); + totalCounts = result.getTotalElements(); + products = result; } else if (manufacturer != null && minPrice == null && maxPrice == null) { /// 카테고리 + 제조사만 있는 경우 - products = productService.getProductsByCategoryIdAndManufacturerId(userId, category.getValue(), manufacturer, pageable); + var result = productService.getProductsByCategoryIdAndManufacturerId(userId, category.getValue(), manufacturer, pageable); + totalCounts = result.getTotalElements(); + products = result; } else if (manufacturer == null && minPrice != null && maxPrice != null) { /// 카테고리 + 가격만 있는 경우 - products = productService.getProductsByCategoryIdAndPrice(userId, category.getValue(), minPrice, maxPrice, pageable); + var result = productService.getProductsByCategoryIdAndPrice(userId, category.getValue(), minPrice, maxPrice, pageable); + totalCounts = result.getTotalElements(); + products = result; } else if (manufacturer != null && minPrice != null && maxPrice != null) { /// 카테고리 + 제조사 + 가격이 있는 경우 - products = productService.getProductsByCategoryIdAndManufacturerIdAndPrice( + var result = productService.getProductsByCategoryIdAndManufacturerIdAndPrice( userId, category.getValue(), manufacturer, minPrice, maxPrice, pageable); + totalCounts = result.getTotalElements(); + products = result; + } else { throw new IllegalArgumentException(ErrorCode.BAD_REQUEST.getMessage()); } - /// 카테고리에 따른 전체 개수 조회 - Long totalCounts = productService.getCountProducts(category.getValue()); - return ApiResponse.ok(SliceResponse.from(products, totalCounts)); } diff --git a/src/main/java/site/kikihi/custom/platform/adapter/in/web/dto/request/custom/CustomKeyboardUpdateRequest.java b/src/main/java/site/kikihi/custom/platform/adapter/in/web/dto/request/custom/CustomKeyboardUpdateRequest.java new file mode 100644 index 0000000..38a565f --- /dev/null +++ b/src/main/java/site/kikihi/custom/platform/adapter/in/web/dto/request/custom/CustomKeyboardUpdateRequest.java @@ -0,0 +1,14 @@ +package site.kikihi.custom.platform.adapter.in.web.dto.request.custom; + +import lombok.Data; + +@Data +public class CustomKeyboardUpdateRequest { + + private Long id; + + private CustomCategoryType category; + + private String productId; + +} diff --git a/src/main/java/site/kikihi/custom/platform/adapter/in/web/dto/response/product/ProductListResponse.java b/src/main/java/site/kikihi/custom/platform/adapter/in/web/dto/response/product/ProductListResponse.java index 5bd1575..505d2fb 100644 --- a/src/main/java/site/kikihi/custom/platform/adapter/in/web/dto/response/product/ProductListResponse.java +++ b/src/main/java/site/kikihi/custom/platform/adapter/in/web/dto/response/product/ProductListResponse.java @@ -82,6 +82,17 @@ public static List from(List products, Set .toList(); } + /// 북마크한 내용이 있을 때, 북마크한 상품목록만 가져오는 정적 팩토리 메서드 + public static List fromBookmark(List products, Set bookmarkProductIds) { + return products.stream() + .map(product -> ProductListResponse.from( + product, + bookmarkProductIds.contains(product.getId()))) + /// true인 것만 가져오게끔 + .filter(ProductListResponse::likedByMe) + .toList(); + } + /// 북마크한 내용이 있을 때 사용하는, 내부 정적 팩토리 메서드 public static ProductListResponse from(Product product, boolean likedByMe) { return ProductListResponse.builder() diff --git a/src/main/java/site/kikihi/custom/platform/adapter/in/web/swagger/CustomKeyboardControllerSpec.java b/src/main/java/site/kikihi/custom/platform/adapter/in/web/swagger/CustomKeyboardControllerSpec.java index ecbe015..2f300a4 100644 --- a/src/main/java/site/kikihi/custom/platform/adapter/in/web/swagger/CustomKeyboardControllerSpec.java +++ b/src/main/java/site/kikihi/custom/platform/adapter/in/web/swagger/CustomKeyboardControllerSpec.java @@ -76,17 +76,6 @@ ApiResponse getCustomKeyboard( ApiResponse> getMyCustoms( @AuthenticationPrincipal PrincipalDetails principalDetails); - - /** - * 키보드 배열 종류 조회 - */ - @Operation( - summary = "키보드 배열 목록 조회 API", - description = "키보드 배열의 목록을 조회합니다." - ) - ApiResponse> getCustomKeyboardLayout(); - - /** * */ @@ -99,6 +88,9 @@ ApiResponse> getCustomKeyboardProductsByLayou @AuthenticationPrincipal PrincipalDetails principalDetails, @RequestParam CustomCategoryType category, @RequestParam CustomKeyboardLayout layout, + @RequestParam(required = false) Integer minPrice, + @RequestParam(required = false) Integer maxPrice, + @RequestParam(required = true) boolean bookmark, PageRequest pageRequest ); diff --git a/src/main/java/site/kikihi/custom/platform/adapter/out/CustomKeyboardAdapter.java b/src/main/java/site/kikihi/custom/platform/adapter/out/CustomKeyboardAdapter.java index d524691..cc4e61f 100644 --- a/src/main/java/site/kikihi/custom/platform/adapter/out/CustomKeyboardAdapter.java +++ b/src/main/java/site/kikihi/custom/platform/adapter/out/CustomKeyboardAdapter.java @@ -68,12 +68,40 @@ public boolean existCustomKeyboardByUserIdAndId(UUID userId, Long id) { return repository.existsByUserIdAndId(userId, id); } + /** + * 커스텀 키보드를 제작했다면 최신의 것 반영 + * @param userId 유저 + */ @Override public Optional loadCustomKeyboardByUserId(UUID userId) { - return repository.findByUserId(userId) + return repository.findByUserId(userId).stream() + .findFirst() .map(CustomKeyboardJpaEntity::toDomain); } + /** + * 커스텀 키보드 내부에 해당 상품 ID가 존재하는지 체크 + * + * @param id 커스텀 ID + * @param productId 상품 ID + */ + @Override + public boolean existProductInsideCustomKeyboard(Long id, String categoryId, String productId) { + + switch (categoryId) { + case "housing": + return repository.existsByIdAndFrameId(id, productId); + case "switch": + return repository.existsByIdAndSwitchId(id, productId); + case "keycap": + return repository.existsByIdAndKeyCapId(id, productId); + case "accessory": + return repository.existsByIdAndAccessoryId(id, productId); + default: + return false; + } + } + // ================= // DB 수정 // ================= @@ -99,4 +127,19 @@ public void updateCustomKeyboard(CustomKeyboard customKeyboard) { public void deleteCustomKeyboard(Long id) { repository.deleteById(id); } + + /** + * 삭제할 커스텀 키보드 + * @param id 아이디 + * @param categoryId 카테고리 + * @param productId 상품 ID + */ + @Override + public void deleteProductInsideCustomKeyboard(Long id, String categoryId, String productId) { + + /// 삭제가 아닌 수정으로 진행 + /// 더티 체킹으로서 수행 + + + } } diff --git a/src/main/java/site/kikihi/custom/platform/adapter/out/ProductMongoAdapter.java b/src/main/java/site/kikihi/custom/platform/adapter/out/ProductMongoAdapter.java index fe40e07..ce6eb25 100644 --- a/src/main/java/site/kikihi/custom/platform/adapter/out/ProductMongoAdapter.java +++ b/src/main/java/site/kikihi/custom/platform/adapter/out/ProductMongoAdapter.java @@ -47,10 +47,10 @@ public Optional getProduct(String productId) { // ================= /// 카테고리 기반 상품 목록 조회 (카테고리만) @Override - public Slice getProducts(String category, Pageable pageable) { + public Page getProducts(String category, Pageable pageable) { /// DB 조회 - Slice result = documentRepository + Page result = documentRepository .findByCategory(category, pageable); return result. @@ -59,7 +59,7 @@ public Slice getProducts(String category, Pageable pageable) { /// 카테고리 기반 상품 목록 조회 (카테고리, 제조사 포함) @Override - public Slice getProducts(String category, List manufacturer, Pageable pageable) { + public Page getProducts(String category, List manufacturer, Pageable pageable) { /// DB 조회 Page result = documentRepository @@ -71,9 +71,9 @@ public Slice getProducts(String category, List manufacturer, Pa /// 카테고리 기반 상품 목록 조회 (카테고리, 가격 포함) @Override - public Slice getProducts(String category, Integer minPrice, Integer maxPrice, Pageable pageable) { + public Page getProducts(String category, Integer minPrice, Integer maxPrice, Pageable pageable) { /// DB 조회 - Slice result = documentRepository + Page result = documentRepository .findByCategoryAndPriceRange(category, minPrice, maxPrice, pageable); return result. @@ -82,11 +82,11 @@ public Slice getProducts(String category, Integer minPrice, Integer max /// 카테고리 기반 상품 목록 조회 (카테고리, 제조사, 가격 포함) @Override - public Slice getProducts(String category, List manufacturer, + public Page getProducts(String category, List manufacturer, Integer minPrice, Integer maxPrice, Pageable pageable) { /// DB 조회 - Slice result = documentRepository + Page result = documentRepository .findByCategoryAndManufacturerAndPriceRange(category, manufacturer, minPrice, maxPrice, pageable); return result. @@ -128,42 +128,56 @@ public Map getProductsByIds(List productIds) { } /** - * 커스텀에서 사용할 함수 + * 커스텀에서 사용할 하우징 함수 * - * @param type 조회할 타입 - * @param pageable 페이징 + * @param type 조회할 타입 + * @param categoryId 카테고리 + * @param pageable 페이징 */ @Override - public Slice getProductsAndCategoryByType(String type, String categoryId, Pageable pageable) { + public Page getCustomProducts(String type, String categoryId, Pageable pageable) { - return documentRepository.findByTypeAndCategoryAndIsCustomTrue(type, categoryId, pageable) + return documentRepository.findByCustomHousing(type, categoryId, pageable) .map(ProductDocument::toDomain); } + /** + * 커스텀에서 사용할 하우징 함수 (가격) + * + * @param type 조회할 타입 + * @param categoryId 카테고리 + * @param minPrice 최소 가격 + * @param maxPrice 최대 가격 + * @param pageable 페이징 + */ @Override - public Long getProductsAndCategoryByType(String type, String categoryId) { - return documentRepository.countByTypeAndCategoryAndIsCustomTrue(type, categoryId); - } - - @Override - public Slice getProductsByCategoryAndCustom(String categoryId, Pageable pageable) { - return documentRepository.findByCategoryAndIsCustomTrue(categoryId, pageable) + public Page getCustomProducts(String type, String categoryId, Integer minPrice, Integer maxPrice, Pageable pageable) { + return documentRepository.findByCustomHousing(type, categoryId, minPrice, maxPrice, pageable) .map(ProductDocument::toDomain); } + /** + * 커스텀에서 사용할 키캡 함수 + * @param categoryId 카테고리 + * @param pageable 페이징 + */ @Override - public Long getProductsByCategoryAndCustom(String categoryId) { - return documentRepository.countByCategoryAndIsCustomTrue(categoryId); + public Page getCustomProducts(String categoryId, Pageable pageable) { + return documentRepository.findByCustomKeyCap(categoryId, pageable) + .map(ProductDocument::toDomain); } - /** - * 상품 개수 조회 - * @param category 카테고리 + * 커스텀에서 사용할 키캡 함수 + * @param categoryId 카테고리 + * @param minPrice 최소 가격 + * @param maxPrice 최대 가격 + * @param pageable 페이징 */ @Override - public Long getProductsCount(String category) { - return documentRepository.countByCategory(category); + public Page getCustomProducts(String categoryId, Integer minPrice, Integer maxPrice, Pageable pageable) { + return documentRepository.findByCustomKeyCap(categoryId, minPrice, maxPrice, pageable) + .map(ProductDocument::toDomain); } // ================= diff --git a/src/main/java/site/kikihi/custom/platform/adapter/out/jpa/custom/CustomKeyboardJpaRepository.java b/src/main/java/site/kikihi/custom/platform/adapter/out/jpa/custom/CustomKeyboardJpaRepository.java index c500254..0e946bb 100644 --- a/src/main/java/site/kikihi/custom/platform/adapter/out/jpa/custom/CustomKeyboardJpaRepository.java +++ b/src/main/java/site/kikihi/custom/platform/adapter/out/jpa/custom/CustomKeyboardJpaRepository.java @@ -15,8 +15,18 @@ public interface CustomKeyboardJpaRepository extends JpaRepository findByUserId(UUID userId); + /// 커스텀의 아이디 및 내부 상품 존재 여부 여러개 매핑 + boolean existsByIdAndFrameId(Long id, String frameId); + boolean existsByIdAndSwitchId(Long id, String switchId); + + boolean existsByIdAndKeyCapId(Long id, String keyCapId); + + boolean existsByIdAndAccessoryId(Long id, String accessoryId); + + /// 해당 유저가 가지고 있는지 체크 boolean existsByUserIdAndId(UUID userId, Long id); boolean existsByUserId(UUID userId); + } diff --git a/src/main/java/site/kikihi/custom/platform/adapter/out/mongo/product/ProductDocumentRepository.java b/src/main/java/site/kikihi/custom/platform/adapter/out/mongo/product/ProductDocumentRepository.java index 8b51a46..91ba53e 100644 --- a/src/main/java/site/kikihi/custom/platform/adapter/out/mongo/product/ProductDocumentRepository.java +++ b/src/main/java/site/kikihi/custom/platform/adapter/out/mongo/product/ProductDocumentRepository.java @@ -13,16 +13,11 @@ public interface ProductDocumentRepository extends MongoRepository { // ================= - // 생성 함수 - // ================= - - - // ================= - // 조회 함수 + // 상품 조회 함수 // ================= /// 카테고리 기반 목록 조회 (카테고리) - Slice findByCategory(String category, Pageable pageable); + Page findByCategory(String category, Pageable pageable); /// 카테고리 기반 목록 조회 (카테고리, 제조사 포함) @Query("{ 'category': ?0, 'manufacturer': { $in: ?1 } }") @@ -35,20 +30,13 @@ public interface ProductDocumentRepository extends MongoRepository findByCategoryAndPriceRange( + Page findByCategoryAndPriceRange( String category, Integer minPrice, Integer maxPrice, Pageable pageable ); - @Aggregation(pipeline = { - "{ '$match': { 'category': ?0 } }", - "{ '$group': { '_id': '$manufacturer' } }" - }) - List findManufacturersByCategory(String category); - - /// 카테고리 기반 목록 조회 (카테고리, 제조사, 가격 포함) @Query(""" { @@ -57,7 +45,7 @@ Slice findByCategoryAndPriceRange( 'price': { $gte: ?2, $lte: ?3 } } """) - Slice findByCategoryAndManufacturerAndPriceRange( + Page findByCategoryAndManufacturerAndPriceRange( String category, List manufacturer, Integer minPrice, @@ -66,6 +54,19 @@ Slice findByCategoryAndManufacturerAndPriceRange( ); + /// 제조사 목록 조회 (카테고리, 가격 포함) + @Aggregation(pipeline = { + "{ '$match': { 'category': ?0 } }", + "{ '$group': { '_id': '$manufacturer' } }" + }) + List findManufacturersByCategory(String category); + + + // ================= + // 카테고리 상품 조회 함수 + // ================= + + /// 카테고리 상품 목록 조회, 하우징 조회 @Query(""" { 'type': ?0, @@ -73,36 +74,61 @@ Slice findByCategoryAndManufacturerAndPriceRange( 'is_custom': true } """) - Slice findByTypeAndCategoryAndIsCustomTrue( + Page findByCustomHousing( String type, String category, Pageable pageable ); - @Query(value = """ - { 'type': ?0, 'category': ?1, 'is_custom': true } -""", count = true) - Long countByTypeAndCategoryAndIsCustomTrue(String type, String category); - + /// 카테고리 상품 목록 조회, 하우징 조회(가격 포함) @Query(""" { - 'category': ?0, + 'type': ?0, + 'category': ?1, + 'price': { $gte: ?2, $lte: ?3 }, 'is_custom': true } """) - Slice findByCategoryAndIsCustomTrue( + Page findByCustomHousing( + String type, String category, + Integer minPrice, + Integer maxPrice, Pageable pageable ); - @Query(value = """ - {'category': ?0, 'is_custom': true } -""", count = true) - Long countByCategoryAndIsCustomTrue(String category); + /// 카테고리 상품 목록 조회, 키캡 조회 + @Query(""" + { + 'category': ?0, + 'is_custom': true + } + """) + Page findByCustomKeyCap( + String category, + Pageable pageable + ); + /// 카테고리 상품 목록 조회, 키캡 조회 + @Query(""" + { + 'category': ?0, + 'price': { $gte: ?1, $lte: ?2 }, + 'is_custom': true + } + """) + Page findByCustomKeyCap( + String category, + Integer minPrice, + Integer maxPrice, + Pageable pageable + ); + // ================= + // 추천용 함수 + // ================= /// 아이디 기반 조회 Slice findByIdIn(List ids, Pageable pageable); @@ -122,9 +148,9 @@ Slice findByCategoryAndIsCustomTrue( }) List findRandomExcludeIds(List excludedIds, int limit); - /// 상품 개수 - Long countByCategory(String category); + // ================= // 삭제 함수 // ================= + } diff --git a/src/main/java/site/kikihi/custom/platform/application/in/custom/CustomKeyboardUseCase.java b/src/main/java/site/kikihi/custom/platform/application/in/custom/CustomKeyboardUseCase.java index fe17586..9100af0 100644 --- a/src/main/java/site/kikihi/custom/platform/application/in/custom/CustomKeyboardUseCase.java +++ b/src/main/java/site/kikihi/custom/platform/application/in/custom/CustomKeyboardUseCase.java @@ -1,5 +1,6 @@ package site.kikihi.custom.platform.application.in.custom; +import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import site.kikihi.custom.platform.adapter.in.web.dto.request.custom.CustomKeyboardRequest; import site.kikihi.custom.platform.adapter.in.web.dto.response.product.ProductListResponse; @@ -24,28 +25,38 @@ */ public interface CustomKeyboardUseCase { - /// 생성 + /// 커스텀 생성 CustomKeyboard saveCustomKeyboard(CustomKeyboardRequest request, UUID userId); - /// 조회 - // 배열 조회 - List getKeyboardLayouts(); + /// 커스텀 조회 + // 나의 커스텀 키보드 상세 조회 + CustomKeyboardWithName getCustomKeyboard(Long customKeyboardId); // 나의 커스텀 키보드 목록 조회 Slice getCustomKeyboards(UUID userId); - // 나의 커스텀 키보드 목록 조회 - CustomKeyboardWithName getCustomKeyboard(Long customKeyboardId); + /// 커스텀 삭제 + void deleteCustomKeyboard(Long customKeyboardId, UUID userId); + + /// 상품 목록 조회 // 배열에 맞는 상품 조회하기 - Slice getCustomProducts(UUID userId, String categoryId, CustomKeyboardLayout type, Pageable pageable); + Page getCustomProducts(UUID userId, String categoryId, CustomKeyboardLayout type, Pageable pageable); - // 배여에 맞는 상품 개수 조회하기 - Long getCustomProductCounts(String categoryId, CustomKeyboardLayout type); + // 배열에 맞는 상품 조회하기 (카테고리, 북마크) + Page getProductsByBookmark(UUID userId, String categoryId, CustomKeyboardLayout type, Pageable pageable); + // 배열에 맞는 상품 가격대 필터링 조회하기 (카테고리, 가격) + Page getProductsByCategoryIdAndPrice(UUID userId, String categoryId, CustomKeyboardLayout type, Integer minPrice, Integer maxPrice, Pageable pageable); - /// 삭제 - void deleteCustomKeyboard(Long customKeyboardId, UUID userId); + // 배열에 맞는 상품 조회하기 (카테고리, 북마크, 가격) + Page getProductsByFilterAndBookmark(UUID userId, String categoryId, CustomKeyboardLayout type, Integer minPrice, Integer maxPrice, Pageable pageable); + + /// 수정 + // 커스텀 상품 내부에 부품 추가하기 + void insertProductInCustomKeyboard(Long customKeyboardId, String categoryId, String productId, UUID userId); + // 커스텀 상품 내부에서 부품 제거하기 + void deleteCustomInside(Long customKeyboardId, String categoryId, String productId, UUID userId); } diff --git a/src/main/java/site/kikihi/custom/platform/application/in/product/ProductUseCase.java b/src/main/java/site/kikihi/custom/platform/application/in/product/ProductUseCase.java index d9f9bf7..97de88e 100644 --- a/src/main/java/site/kikihi/custom/platform/application/in/product/ProductUseCase.java +++ b/src/main/java/site/kikihi/custom/platform/application/in/product/ProductUseCase.java @@ -1,5 +1,6 @@ package site.kikihi.custom.platform.application.in.product; +import org.springframework.data.domain.Page; import site.kikihi.custom.platform.adapter.in.web.dto.response.product.ProductDetailResponse; import site.kikihi.custom.platform.adapter.in.web.dto.response.product.ProductListResponse; import site.kikihi.custom.platform.domain.custom.CustomKeyboardLayout; @@ -20,19 +21,16 @@ public interface ProductUseCase { /// 상품 목록 조회 // 카테고리별 목록 조회 (카테고리 포함) - mongoDB - Slice getProductsByCategoryId(UUID userId, String categoryId, Pageable pageable); + Page getProductsByCategoryId(UUID userId, String categoryId, Pageable pageable); // 카테고리별 목록 조회 (카테고리, 제조사 포함) - Slice getProductsByCategoryIdAndManufacturerId(UUID userId, String categoryId, List manufacturerId, Pageable pageable); + Page getProductsByCategoryIdAndManufacturerId(UUID userId, String categoryId, List manufacturerId, Pageable pageable); // 카테고리별 목록 조회 (카테고리, 가격 포함) - Slice getProductsByCategoryIdAndPrice(UUID userId, String categoryId, Integer minPrice, Integer maxPrice, Pageable pageable); + Page getProductsByCategoryIdAndPrice(UUID userId, String categoryId, Integer minPrice, Integer maxPrice, Pageable pageable); // 카테고리별 목록 조회 (카테고리, 제조사, 가격 포함) - Slice getProductsByCategoryIdAndManufacturerIdAndPrice(UUID userId, String categoryId, List manufacturer, Integer minPrice, Integer maxPrice, Pageable pageable); - - /// 상품 개수 조회 - Long getCountProducts(String categoryId); + Page getProductsByCategoryIdAndManufacturerIdAndPrice(UUID userId, String categoryId, List manufacturer, Integer minPrice, Integer maxPrice, Pageable pageable); /// 상품 상세 조회 ProductDetailResponse getProduct(UUID userId, String id); @@ -40,9 +38,4 @@ public interface ProductUseCase { /// 카테고리 목록 조회 Slice getManufacturers(String categoryId, Pageable pageable); - /// 외부 의존성 - // 커스텀 키보드에 맞는 부품들 조회 - Slice getProductsByLayout(UUID userId, String categoryId, CustomKeyboardLayout layout, Pageable pageable); - - } diff --git a/src/main/java/site/kikihi/custom/platform/application/out/custom/CustomKeyboardPort.java b/src/main/java/site/kikihi/custom/platform/application/out/custom/CustomKeyboardPort.java index b7c3bad..16dbbc8 100644 --- a/src/main/java/site/kikihi/custom/platform/application/out/custom/CustomKeyboardPort.java +++ b/src/main/java/site/kikihi/custom/platform/application/out/custom/CustomKeyboardPort.java @@ -24,11 +24,15 @@ public interface CustomKeyboardPort { // 존재 여부 판단 Optional loadCustomKeyboardByUserId(UUID userId); + // 상품이 커스텀 내부 존재 여부 판단 + boolean existProductInsideCustomKeyboard(Long id, String categoryId, String productId); + /// 수정 void updateCustomKeyboard(CustomKeyboard customKeyboard); - /// 삭제 void deleteCustomKeyboard(Long id); + void deleteProductInsideCustomKeyboard(Long id, String categoryId, String productId); + } diff --git a/src/main/java/site/kikihi/custom/platform/application/out/product/ProductPort.java b/src/main/java/site/kikihi/custom/platform/application/out/product/ProductPort.java index 8c4739c..dc01543 100644 --- a/src/main/java/site/kikihi/custom/platform/application/out/product/ProductPort.java +++ b/src/main/java/site/kikihi/custom/platform/application/out/product/ProductPort.java @@ -1,5 +1,6 @@ package site.kikihi.custom.platform.application.out.product; +import org.springframework.data.domain.Page; import site.kikihi.custom.platform.domain.custom.CustomKeyboardLayout; import site.kikihi.custom.platform.domain.product.Product; import org.springframework.data.domain.Pageable; @@ -24,42 +25,34 @@ public interface ProductPort { // 상품 목록 조회 // ================= /// 카테고리 기반 상품 목록 조회 (카테고리만) - Slice getProducts(String category, Pageable pageable); + Page getProducts(String category, Pageable pageable); /// 카테고리 기반 상품 목록 조회 (카테고리, 제조사 포함) - Slice getProducts(String category, List manufacturer, Pageable pageable); + Page getProducts(String category, List manufacturer, Pageable pageable); /// 카테고리 기반 상품 목록 조회 (카테고리, 제조사 포함) - Slice getProducts(String category, Integer minPrice, Integer maxPrice, Pageable pageable); + Page getProducts(String category, Integer minPrice, Integer maxPrice, Pageable pageable); /// 카테고리 기반 상품 목록 조회 (카테고리, 제조사, 가격 포함) - Slice getProducts(String category, List manufacturer, Integer minPrice, Integer maxPrice, Pageable pageable); + Page getProducts(String category, List manufacturer, Integer minPrice, Integer maxPrice, Pageable pageable); /// 카테고리 기반 제조사 조회 List getManufacturers(String category); - // ================= - // 상품 조회 + // 카테고리 상품 목록 조회 // ================= - /// 상품 ID들 바탕으로 조회 - Slice getProductsByIds(List productIds, Pageable pageable); - - /// 상품 ID들 바탕으로 조회 - Map getProductsByIds(List productIds); - - Slice getProductsAndCategoryByType(String type, String categoryId, Pageable pageable); + /// 카테고리 기반 상품 목록 조회 (카테고리, 타입) + Page getCustomProducts(String type, String categoryId, Pageable pageable); - // 개수 - Long getProductsAndCategoryByType(String type, String categoryId); + /// 카테고리 기반 상품 목록 조회 (카테고리, 타입, 가격) + Page getCustomProducts(String type, String categoryId, Integer minPrice, Integer maxPrice, Pageable pageable); - Slice getProductsByCategoryAndCustom(String categoryId, Pageable pageable); + /// 카테고리 기반 상품 목록 조회 (카테고리) + Page getCustomProducts(String categoryId, Pageable pageable); - // 개수 - Long getProductsByCategoryAndCustom(String categoryId); - - /// 상품 개수 조회 - Long getProductsCount(String category); + /// 카테고리 기반 상품 목록 조회 (카테고리, 가격) + Page getCustomProducts(String categoryId, Integer minPrice, Integer maxPrice, Pageable pageable); // ================= // 상품 추천 @@ -74,6 +67,16 @@ public interface ProductPort { /// 비슷한 상품 추천 List findProductsByAttributes(String switchId, String keycapId, CustomKeyboardLayout layout); + // ================= + // 상품 조회 + // ================= + /// 상품 ID들 바탕으로 조회 + Slice getProductsByIds(List productIds, Pageable pageable); + + /// 상품 ID들 바탕으로 조회 + Map getProductsByIds(List productIds); + + // ================= // 상품 삭제 // ================= diff --git a/src/main/java/site/kikihi/custom/platform/application/service/CustomKeyboardService.java b/src/main/java/site/kikihi/custom/platform/application/service/CustomKeyboardService.java index 49c55f0..2eabaab 100644 --- a/src/main/java/site/kikihi/custom/platform/application/service/CustomKeyboardService.java +++ b/src/main/java/site/kikihi/custom/platform/application/service/CustomKeyboardService.java @@ -1,7 +1,7 @@ package site.kikihi.custom.platform.application.service; import lombok.extern.slf4j.Slf4j; -import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.*; import site.kikihi.custom.global.response.ErrorCode; import site.kikihi.custom.platform.adapter.in.web.dto.request.custom.CustomKeyboardRequest; import site.kikihi.custom.platform.adapter.in.web.dto.request.product.CategoryType; @@ -18,8 +18,6 @@ import site.kikihi.custom.platform.domain.product.Product; import site.kikihi.custom.platform.domain.user.User; import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Slice; -import org.springframework.data.domain.SliceImpl; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -76,20 +74,23 @@ public CustomKeyboard saveCustomKeyboard(CustomKeyboardRequest request, UUID use return port.saveCustomKeyboard(customKeyboard); } - // ================= - // 조회 함수 - // ================= - - // 배열 조회 /** - * 키보드 레이아웃을 조회 + * 상품 부품 추가하기 + * @param customKeyboardId 커스텀 키보드 ID + * @param categoryId 추가할 카테고리 + * @param productId 추가할 상품 ID + * @param userId 유저 */ @Override - public List getKeyboardLayouts() { - return CustomKeyboardLayout.getKeyboardLayouts(); + public void insertProductInCustomKeyboard(Long customKeyboardId, String categoryId, String productId, UUID userId) { + } + // ================= + // 조회 함수 + // ================= + /** * 내가 만든 키보드 목록 조회 @@ -173,25 +174,25 @@ public CustomKeyboardWithName getCustomKeyboard(Long customKeyboardId) { } /** - * 키보드 배열을 바탕으로 가능한 상품 목록 조회 + * 키보드 배열을 바탕으로 가능한 상품 목록 조회 (카테고리) * * @param userId 유저ID * @param type 조회할 배열 타입 * @param pageable 페이징 */ @Override - public Slice getCustomProducts(UUID userId, String categoryId, CustomKeyboardLayout type, Pageable pageable) { + public Page getCustomProducts(UUID userId, String categoryId, CustomKeyboardLayout type, Pageable pageable) { - Slice products; + Page products; /// 타입을 바탕으로 조회하기 /// 하우징인 경우 if (categoryId.equals(CategoryType.HOUSING.getValue())){ - products = productPort.getProductsAndCategoryByType(type.getDb(), categoryId, pageable); + products = productPort.getCustomProducts(type.getDb(), categoryId, pageable); } /// 키캡인 경우 else if (categoryId.equals(CategoryType.KEYCAP.getValue())) { - products = productPort.getProductsByCategoryAndCustom(categoryId, pageable); + products = productPort.getCustomProducts(categoryId, pageable); } else { products = productPort.getProducts(categoryId, pageable); } @@ -200,27 +201,94 @@ else if (categoryId.equals(CategoryType.KEYCAP.getValue())) { return toProductListResponse(userId, categoryId, products); } + /** + * 키보드 배열을 바탕으로 상품 목록 조회 (카테고리,북마크) + * @param userId 유저ID + * @param categoryId 카테고리 + * @param type 조회할 타입 + * @param pageable 페이징 + */ + @Override + public Page getProductsByBookmark(UUID userId, String categoryId, CustomKeyboardLayout type, Pageable pageable) { + Page products; + + /// 타입을 바탕으로 조회하기 + /// 하우징인 경우 + if (categoryId.equals(CategoryType.HOUSING.getValue())){ + products = productPort.getCustomProducts(type.getDb(), categoryId, pageable); + } + /// 키캡인 경우 + else if (categoryId.equals(CategoryType.KEYCAP.getValue())) { + products = productPort.getCustomProducts(categoryId, pageable); + } else { + products = productPort.getProducts(categoryId, pageable); + } + + /// 북마크 여부 파악해서 해당 상품만 가져오기 + return toProductBookmarkResponse(userId, categoryId, products); + } + + /** + * 키보드 배열을 바탕으로 상품 목록의 필터링 조회 (카테고리, 가격) + * @param userId 유저 ID + * @param categoryId 카테고리 ID + * @param minPrice 최소가격 + * @param maxPrice 최대가격 + * @param pageable 페이징 + */ + @Override + public Page getProductsByCategoryIdAndPrice(UUID userId, String categoryId, CustomKeyboardLayout type, Integer minPrice, Integer maxPrice, Pageable pageable) { + + /// Port에서 조회 + Page products; + + /// 하우징인 경우 + if (categoryId.equals(CategoryType.HOUSING.getValue())){ + products = productPort.getCustomProducts(type.getDb(), categoryId, minPrice, maxPrice, pageable); + } + /// 키캡인 경우 + else if (categoryId.equals(CategoryType.KEYCAP.getValue())) { + products = productPort.getCustomProducts(categoryId, minPrice, maxPrice, pageable); + + } else { + products = productPort.getProducts(categoryId, minPrice, maxPrice, pageable); + } + + /// 북마크 여부 파악해서 해당 상품만 가져오기 + return toProductListResponse(userId, categoryId, products); + } /** - * 키보드 배열을 바탕으로 가능한 상품 개수 조회 + * 키보드 배열을 바탕으로 상품 목록의 필터링 조회 (카테고리,북마크,가격) * + * @param userId 유저 ID + * @param categoryId 카테고리 ID + * @param minPrice 최소가격 + * @param maxPrice 최대가격 + * @param pageable 페이징 */ @Override - public Long getCustomProductCounts(String categoryId, CustomKeyboardLayout type) { + public Page getProductsByFilterAndBookmark(UUID userId, String categoryId, CustomKeyboardLayout type, Integer minPrice, Integer maxPrice, Pageable pageable) { + /// Port에서 조회 + Page products; - /// 타입을 바탕으로 조회하기 /// 하우징인 경우 if (categoryId.equals(CategoryType.HOUSING.getValue())){ - return productPort.getProductsAndCategoryByType(type.getDb(), categoryId); + products = productPort.getCustomProducts(type.getDb(), categoryId, minPrice, maxPrice, pageable); } /// 키캡인 경우 else if (categoryId.equals(CategoryType.KEYCAP.getValue())) { - return productPort.getProductsByCategoryAndCustom(categoryId); + products = productPort.getCustomProducts(categoryId, minPrice, maxPrice, pageable); + } else { - return productPort.getProductsCount(categoryId); + products = productPort.getProducts(categoryId, minPrice, maxPrice, pageable); } + + /// 북마크 여부 파악해서 해당 상품만 가져오기 + return toProductBookmarkResponse(userId, categoryId, products); } + // ================= // 삭제 함수 // ================= @@ -228,6 +296,7 @@ else if (categoryId.equals(CategoryType.KEYCAP.getValue())) { /** * 커스텀 키보드 삭제 * @param customKeyboardId 삭제할 커스텀 ID + * @param userId 삭제하는 유저 ID */ @Override public void deleteCustomKeyboard(Long customKeyboardId, UUID userId) { @@ -245,6 +314,37 @@ public void deleteCustomKeyboard(Long customKeyboardId, UUID userId) { } + /** + * 커스텀 키보드 내부에 있는 부품을 삭제합니다 + * + * @param customKeyboardId 삭제할 커스텀 ID + * @param categoryId 카테고리 ID + * @param productId 부품 ID + * @param userId 삭제하는 유저 ID + */ + @Override + public void deleteCustomInside(Long customKeyboardId, String categoryId, String productId, UUID userId) { + + /// 해당 유저의 커스텀 키보드인지 체크 + boolean checked = port.existCustomKeyboardByUserIdAndId(userId, customKeyboardId); + + /// 키보드가 요청자의 것이 아니라면 에러 발생 + if (!checked) { + throw new IllegalStateException(ErrorCode.UNAUTHORIZED_DELETE_CUSTOM.getMessage()); + } + + /// 커스텀 내부에 해당 상품의 ID가 있는지 여부 확인 + boolean existed = port.existProductInsideCustomKeyboard(customKeyboardId, categoryId, productId); + + if (!existed) { + throw new IllegalStateException(ErrorCode.BAD_PRODUCT_DELETE_CUSTOM.getMessage()); + } + + /// 해당 유저의 상품이며, 커스텀 내부에 상품이 존재하기에 삭제 가능하다. + port.deleteCustomKeyboard(customKeyboardId); + + } + // ================= // 공통 함수 @@ -296,7 +396,7 @@ private CustomKeyboard getKeyboard(Long customKeyboardId) { * @param categoryId 카테고리 ID * @param products 상품 목록 */ - private Slice toProductListResponse(UUID userId, String categoryId, Slice products) { + private Page toProductListResponse(UUID userId, String categoryId, Page products) { /// 응답 값 List dtoList; @@ -310,7 +410,7 @@ private Slice toProductListResponse(UUID userId, String cat dtoList = ProductListResponse.from(content); /// 새로운 Slice 객체로 생성 - return new SliceImpl<>(dtoList, products.getPageable(), products.hasNext()); + return new PageImpl<>(dtoList, products.getPageable(), products.getTotalElements()); } /// 유저가 북마크를 했는지 체크 @@ -324,7 +424,46 @@ private Slice toProductListResponse(UUID userId, String cat // 북마크 여부 반영하여 DTO 변환 dtoList = ProductListResponse.from(content, bookmarkedProductIds); - return new SliceImpl<>(dtoList, products.getPageable(), products.hasNext()); + return new PageImpl<>(dtoList, products.getPageable(), products.getTotalElements()); + } + + // ================= + // 공통 함수 + // ================= + /** + * 상품 목록 조회를 진행할때, 북마크 여부를 파악하는 함수입니다. + * @param userId 유저 ID + * @param categoryId 카테고리 ID + * @param products 상품 목록 + */ + private Page toProductBookmarkResponse(UUID userId, String categoryId, Page products) { + /// 응답 값 + List dtoList; + + /// 상품 목록 꺼내서 DTO 변환 + List content = products.getContent(); + + /// 로그인 하지 않은 유저가 확인한다면 + if (userId == null) { + + dtoList = List.of(); + + /// 새로운 Slice 객체로 생성 + return new PageImpl<>(dtoList, products.getPageable(), products.getTotalElements()); + } + + /// 유저가 북마크를 했는지 체크 + List bookmarks = bookmarkPort.getBookmarksByUserIdAndCategoryId(userId, categoryId); + + /// 북마크된 상품 ID만 추출 + Set bookmarkedProductIds = bookmarks.stream() + .map(Bookmark::getProductId) + .collect(Collectors.toSet()); + + // 북마크 여부 반영하여 DTO 변환 + dtoList = ProductListResponse.fromBookmark(content, bookmarkedProductIds); + + return new PageImpl<>(dtoList, products.getPageable(), products.getTotalElements()); } } diff --git a/src/main/java/site/kikihi/custom/platform/application/service/ProductService.java b/src/main/java/site/kikihi/custom/platform/application/service/ProductService.java index 88a8f20..0c61d31 100644 --- a/src/main/java/site/kikihi/custom/platform/application/service/ProductService.java +++ b/src/main/java/site/kikihi/custom/platform/application/service/ProductService.java @@ -1,5 +1,6 @@ package site.kikihi.custom.platform.application.service; +import org.springframework.data.domain.*; import site.kikihi.custom.global.response.ErrorCode; import site.kikihi.custom.platform.adapter.in.web.dto.response.product.ProductDetailResponse; import site.kikihi.custom.platform.adapter.in.web.dto.response.product.ProductListResponse; @@ -7,13 +8,9 @@ import site.kikihi.custom.platform.application.out.bookmark.BookmarkPort; import site.kikihi.custom.platform.application.out.product.ProductPort; import site.kikihi.custom.platform.domain.bookmark.Bookmark; -import site.kikihi.custom.platform.domain.custom.CustomKeyboardLayout; import site.kikihi.custom.platform.domain.product.Product; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; -import org.springframework.data.domain.SliceImpl; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -50,10 +47,10 @@ public class ProductService implements ProductUseCase { * @param pageable 페이지 */ @Override - public Slice getProductsByCategoryId(UUID userId, String categoryId, Pageable pageable) { + public Page getProductsByCategoryId(UUID userId, String categoryId, Pageable pageable) { /// Port에서 조회 - Slice products = productPort.getProducts(categoryId, pageable); + Page products = productPort.getProducts(categoryId, pageable); /// 공통 함수 바탕으로 처리 return toProductListResponse(userId, categoryId, products); @@ -68,10 +65,10 @@ public Slice getProductsByCategoryId(UUID userId, String ca * @param pageable 페이지 */ @Override - public Slice getProductsByCategoryIdAndManufacturerId(UUID userId, String categoryId, List manufacturers, Pageable pageable) { + public Page getProductsByCategoryIdAndManufacturerId(UUID userId, String categoryId, List manufacturers, Pageable pageable) { /// Port에서 조회 - Slice products = productPort.getProducts(categoryId, manufacturers, pageable); + Page products = productPort.getProducts(categoryId, manufacturers, pageable); /// 공통 함수 바탕으로 처리 return toProductListResponse(userId, categoryId, products); @@ -89,10 +86,10 @@ public Slice getProductsByCategoryIdAndManufacturerId(UUID * @param pageable 페이지 */ @Override - public Slice getProductsByCategoryIdAndPrice(UUID userId, String categoryId, Integer minPrice, Integer maxPrice, Pageable pageable) { + public Page getProductsByCategoryIdAndPrice(UUID userId, String categoryId, Integer minPrice, Integer maxPrice, Pageable pageable) { /// Port에서 조회 - Slice products = productPort.getProducts(categoryId, minPrice, maxPrice, pageable); + Page products = productPort.getProducts(categoryId, minPrice, maxPrice, pageable); /// 공통 함수 바탕으로 처리 return toProductListResponse(userId, categoryId, products); @@ -110,26 +107,15 @@ public Slice getProductsByCategoryIdAndPrice(UUID userId, S * @param pageable 페이지 */ @Override - public Slice getProductsByCategoryIdAndManufacturerIdAndPrice(UUID userId, String categoryId, List manufacturers, Integer minPrice, Integer maxPrice, Pageable pageable) { + public Page getProductsByCategoryIdAndManufacturerIdAndPrice(UUID userId, String categoryId, List manufacturers, Integer minPrice, Integer maxPrice, Pageable pageable) { /// Port에서 조회 - Slice products = productPort.getProducts(categoryId, manufacturers, minPrice, maxPrice, pageable); + Page products = productPort.getProducts(categoryId, manufacturers, minPrice, maxPrice, pageable); /// 공통 함수 바탕으로 처리 return toProductListResponse(userId, categoryId, products); } - /** - * 카테고리에 따른 전체 상품 개수 - * @param categoryId 카테고리 - */ - @Override - public Long getCountProducts(String categoryId) { - - /// Port에서 조회 - return productPort.getProductsCount(categoryId); - } - // ================= // 상품 상세 조회 // ================= @@ -184,29 +170,6 @@ public Slice getManufacturers(String categoryId, Pageable pageable) { // ======================== // 외부 의존성 - // ======================== - /** - * 커스텀 키보드에 맞는 부품들 조회 - * @param userId 북마크 체크를 위한 유저ID - * @param categoryId 카테고리 ID - * @param layout 생성할 커스텀 키보드 배열 - * @param pageable 페이징 - */ - @Override - public Slice getProductsByLayout(UUID userId, String categoryId, CustomKeyboardLayout layout, Pageable pageable) { - - /// Port에서 조회 - Slice products = productPort.getProducts(categoryId, pageable); - - // TODO!필터 작업이 필요하다!! - /// 필터를 통해 해당 제품이 특정 배열이 가능한 것만 가져오기 -// products.stream() -// .filter()... - - /// 결과 리턴 - /// - return toProductListResponse(userId, categoryId, products); - } // ================= // 공통 함수 @@ -217,7 +180,7 @@ public Slice getProductsByLayout(UUID userId, String catego * @param categoryId 카테고리 ID * @param products 상품 목록 */ - private Slice toProductListResponse(UUID userId, String categoryId, Slice products) { + private Page toProductListResponse(UUID userId, String categoryId, Page products) { /// 응답 값 List dtoList; @@ -231,7 +194,7 @@ private Slice toProductListResponse(UUID userId, String cat dtoList = ProductListResponse.from(content); /// 새로운 Slice 객체로 생성 - return new SliceImpl<>(dtoList, products.getPageable(), products.hasNext()); + return new PageImpl<>(dtoList, products.getPageable(), products.getTotalElements()); } /// 유저가 북마크를 했는지 체크 @@ -245,7 +208,7 @@ private Slice toProductListResponse(UUID userId, String cat // 북마크 여부 반영하여 DTO 변환 dtoList = ProductListResponse.from(content, bookmarkedProductIds); - return new SliceImpl<>(dtoList, products.getPageable(), products.hasNext()); + return new PageImpl<>(dtoList, products.getPageable(), products.getTotalElements()); }