Skip to content

Commit

Permalink
Merge pull request #41 from SWM-WeLike2Coding/feat/productIdList
Browse files Browse the repository at this point in the history
feat: 여러 상품 id로 해당 상품 리스트를 조회하는 기능 개발
  • Loading branch information
kjungw1025 authored Jul 31, 2024
2 parents e54bdf5 + 86bb013 commit 8a21659
Show file tree
Hide file tree
Showing 4 changed files with 47 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
@@ -0,0 +1,20 @@
package com.wl2c.elswhereproductservice.domain.product.model.dto.request;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

import java.util.List;

@Getter
public class RequestProductIdListDto {

@Schema(description = "상품 id 리스트", example = "[3, 6, 9, 12]")
private final List<Long> productIdList;

@JsonCreator
public RequestProductIdListDto(@JsonProperty("productIdList") List<Long> productIdList) {
this.productIdList = productIdList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public interface ProductRepository extends JpaRepository<Product, Long> {
"order by case when :sortType = 'knock-in' and p.knockIn is null then 1 else 0 end ")
Page<Product> listByEndSale(@Param("sortType") String sortType, Pageable pageable);

@Query("select p from Product p " +
"where p.productState = 'ACTIVE' " +
"and p.id in :productIdList ")
List<Product> listByIds(@Param("productIdList") List<Long> productIdList);

@Query("select p from Product p where p.productState = 'ACTIVE' and p.id = :id ")
Optional<Product> findOne(@Param("id") Long id);

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 8a21659

Please sign in to comment.