Skip to content

Commit

Permalink
edit : 상품 중분류 별 조회 시 무한스크롤 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
bongsh0112 committed Dec 21, 2023
1 parent 6cafb74 commit af2c15a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.api.annotations.ParameterObject;
Expand All @@ -17,7 +16,6 @@
import org.springframework.web.bind.annotation.RestController;
import tify.server.api.common.slice.SliceResponse;
import tify.server.api.product.model.dto.ProductFilterCondition;
import tify.server.api.product.model.vo.ProductRetrieveVo;
import tify.server.api.product.service.CrawlingUseCase;
import tify.server.api.product.service.ProductSearchUseCase;
import tify.server.api.product.service.RetrieveProductListUseCase;
Expand Down Expand Up @@ -61,10 +59,10 @@ public SliceResponse<ProductRetrieveDTO> productSearch(
return productSearchUseCase.execute(keyword, pageable);
}

@Operation(summary = "SmallCategory(FE기준 중분류) 별 상품을 조회합니다.")
@Operation(summary = "SmallCategory(FE기준 중분류) 별 상품을 조회합니다. (무한스크롤 X)")
@GetMapping("/products/small-category")
public List<ProductRetrieveVo> getCategoricalProduct(
@ParameterObject ProductFilterCondition productFilterCondition) {
return retrieveProductListUseCase.executeToSmallCategory(productFilterCondition);
public SliceResponse<ProductRetrieveDTO> getCategoricalProduct(
@ParameterObject ProductFilterCondition productFilterCondition, Pageable pageable) {
return retrieveProductListUseCase.executeToSmallCategory(productFilterCondition, pageable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import java.util.Collections;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.SliceImpl;
import org.springframework.transaction.annotation.Transactional;
import tify.server.api.common.slice.SliceResponse;
import tify.server.api.product.model.dto.ProductFilterCondition;
import tify.server.api.product.model.vo.ProductRetrieveVo;
import tify.server.core.annotation.UseCase;
import tify.server.domain.domains.product.adaptor.ProductAdaptor;
import tify.server.domain.domains.product.domain.PriceFilter;
Expand All @@ -25,8 +28,8 @@ public class RetrieveProductListUseCase {
private final FavorQuestionAdaptor favorQuestionAdaptor;

@Transactional(readOnly = true)
public List<ProductRetrieveVo> executeToSmallCategory(
ProductFilterCondition productFilterCondition) {
public SliceResponse<ProductRetrieveDTO> executeToSmallCategory(
ProductFilterCondition productFilterCondition, Pageable pageable) {
List<Long> categoryIdList = new ArrayList<>();
productFilterCondition
.getSmallCategoryList()
Expand All @@ -37,17 +40,22 @@ public List<ProductRetrieveVo> executeToSmallCategory(
.map(FavorQuestionCategory::getId)
.toList());
});
List<ProductRetrieveDTO> results =
productAdaptor.findAllBySmallCategoryId(

Slice<ProductRetrieveDTO> productRetrieveDTOS =
productAdaptor.searchBySmallCategoryId(
new ProductCategoryCondition(
categoryIdList,
productFilterCondition.getPriceOrder(),
productFilterCondition.getPriceFilter(),
null));
pageable));
if (productFilterCondition.getPriceOrder().equals(PriceOrder.DEFAULT)
&& productFilterCondition.getPriceFilter().equals(PriceFilter.DEFAULT)) {
Collections.shuffle(results); // TODO : 추천 전략을 적용하는 부분일듯
List<ProductRetrieveDTO> result = productRetrieveDTOS.toList();
Collections.shuffle(result);

Slice<ProductRetrieveDTO> shuffledResult = new SliceImpl<>(result, pageable, true);
return SliceResponse.of(shuffledResult);
}
return results.stream().map(ProductRetrieveVo::from).toList();
return SliceResponse.of(productRetrieveDTOS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,10 @@ public Slice<ProductRetrieveDTO> searchBySmallCategory(
queryFactory
.select(
Projections.constructor(
ProductRetrieveDTO.class,
product.id,
product.name,
product.brand,
product.characteristic,
product.price,
product.productOption,
product.imageUrl,
product.crawlUrl))
ProductRetrieveDTO.class, product, favorQuestionCategory))
.from(product)
.join(favorQuestionCategory)
.on(product.favorQuestionCategoryId.eq(favorQuestionCategory.id))
.where(
product.favorQuestionCategoryId.in(
productCategoryCondition.getCategoryIdList()),
Expand Down

0 comments on commit af2c15a

Please sign in to comment.