Skip to content

Commit

Permalink
feat: 여러 상품 id로 해당 상품 리스트를 조회하는 기능에 대한 컨트롤러 및 서비스 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kjungw1025 committed Jul 31, 2024
1 parent c3b8448 commit 86bb013
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wl2c.elswhereproductservice.domain.product.controller;

import com.wl2c.elswhereproductservice.domain.product.model.dto.list.SummarizedProductDto;
import com.wl2c.elswhereproductservice.domain.product.model.dto.request.RequestProductIdListDto;
import com.wl2c.elswhereproductservice.domain.product.model.dto.request.RequestProductSearchDto;
import com.wl2c.elswhereproductservice.domain.product.model.dto.response.ResponseMaturityRepaymentEvaluationDateDto;
import com.wl2c.elswhereproductservice.domain.product.model.dto.response.ResponseNextRepaymentEvaluationDateDto;
Expand Down Expand Up @@ -71,6 +72,20 @@ public ResponsePage<SummarizedProductDto> listByEndSale(@RequestParam(name = "ty
return new ResponsePage<>(result);
}

/**
* 여러 상품 id로 해당 상품 리스트 조회
* <p>
* 참고 : user-service와 product-service 통신 간에 사용하고자 만든 API 입니다.
* </p>
*
* @param requestProductIdListDto 조회하고자 하는 상품 id 리스트
* @return 상품 리스트
*/
@PostMapping("/list")
public List<SummarizedProductDto> listByProductIds(@Valid @RequestBody RequestProductIdListDto requestProductIdListDto) {
return productService.listByProductIds(requestProductIdListDto.getProductIdList());
}

/**
* 상품 단건 조회
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ public Page<SummarizedProductDto> listByEndSale(String type, Pageable pageable)
return products.map(SummarizedProductDto::new);
}

public List<SummarizedProductDto> listByProductIds(List<Long> productIdList) {
List<Product> productList = productRepository.listByIds(productIdList);

return productList.stream()
.map(SummarizedProductDto::new)
.collect(Collectors.toList());
}

public ResponseSingleProductDto findOne(Long id) {
Product product = productRepository.findOne(id).orElseThrow(ProductNotFoundException::new);
Expand Down

0 comments on commit 86bb013

Please sign in to comment.