Skip to content

Commit

Permalink
Merge pull request #57 from SWM-WeLike2Coding/feat/holdingProduct
Browse files Browse the repository at this point in the history
feat: 보유 상품 리스트 조회를 위한 필요한 기능 추가
  • Loading branch information
kjungw1025 authored Aug 26, 2024
2 parents 75d786e + 60cfdbe commit c091de7
Show file tree
Hide file tree
Showing 3 changed files with 78 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.list.SummarizedProductForHoldingDto;
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;
Expand Down Expand Up @@ -86,6 +87,20 @@ public List<SummarizedProductDto> listByProductIds(@Valid @RequestBody RequestPr
return productService.listByProductIds(requestProductIdListDto.getProductIdList());
}

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

/**
* 상품 단건 조회
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.wl2c.elswhereproductservice.domain.product.model.dto.list;

import com.querydsl.core.annotations.QueryProjection;
import com.wl2c.elswhereproductservice.domain.product.model.ProductType;
import com.wl2c.elswhereproductservice.domain.product.model.entity.Product;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

import java.math.BigDecimal;
import java.time.LocalDate;

@Getter
public class SummarizedProductForHoldingDto {
@Schema(description = "상품 id", example = "1")
private final Long id;

@Schema(description = "발행 회사", example = "oo투자증권")
private final String issuer;

@Schema(description = "상품명", example = "oo투자증권 99999")
private final String name;

@Schema(description = "상품 유형", example = "STEP_DOWN or LIZARD or MONTHLY_PAYMENT or ETC")
private final ProductType productType;

@Schema(description = "기초자산", example = "KOSPI200 Index / HSCEI Index / S&P500 Index")
private final String equities;

@Schema(description = "수익률", example = "20.55")
private final BigDecimal yieldIfConditionsMet;

@Schema(description = "다음 상환평가일", example = "2027-01-13")
private final LocalDate nextRepaymentEvaluationDate;

public SummarizedProductForHoldingDto(Product product,
LocalDate nextRepaymentEvaluationDate) {
this.id = product.getId();
this.issuer = product.getIssuer();
this.name = product.getName();
this.productType = product.getType();
this.equities = product.getEquities();
this.yieldIfConditionsMet = product.getYieldIfConditionsMet();
this.nextRepaymentEvaluationDate = nextRepaymentEvaluationDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.wl2c.elswhereproductservice.domain.product.exception.ProductNotFoundException;
import com.wl2c.elswhereproductservice.domain.product.exception.WrongProductSortTypeException;
import com.wl2c.elswhereproductservice.domain.product.model.dto.list.SummarizedProductDto;
import com.wl2c.elswhereproductservice.domain.product.model.dto.list.SummarizedProductForHoldingDto;
import com.wl2c.elswhereproductservice.domain.product.model.dto.request.RequestProductSearchDto;
import com.wl2c.elswhereproductservice.domain.product.model.dto.response.ResponseProductComparisonTargetDto;
import com.wl2c.elswhereproductservice.domain.product.model.dto.response.ResponseSingleProductDto;
Expand Down Expand Up @@ -35,6 +36,8 @@ public class ProductService {
private final TickerSymbolRepository tickerSymbolRepository;
private final ProductSearchRepository productSearchRepository;

private final RepaymentEvaluationDatesService repaymentEvaluationDatesService;

public Page<SummarizedProductDto> listByOnSale(String type, Pageable pageable) {
Sort sort = switch (type) {
case "latest" -> Sort.by(Sort.Order.desc("subscriptionStartDate"), Sort.Order.desc("lastModifiedAt"));
Expand Down Expand Up @@ -81,6 +84,21 @@ public List<SummarizedProductDto> listByProductIds(List<Long> productIdList) {
.collect(Collectors.toList());
}

public List<SummarizedProductForHoldingDto> holdingListByProductIds(List<Long> productIdList) {
log.info("Before adding the products data");
List<Product> productList = productRepository.listByIds(productIdList);
log.info("After adding the products data");

List<SummarizedProductForHoldingDto> summarizedProductForHoldingDtos = new ArrayList<>();
for (Product product : productList) {
summarizedProductForHoldingDtos.add(new SummarizedProductForHoldingDto(
product,
repaymentEvaluationDatesService.findNextRepaymentEvaluationDate(product.getId()).getNextRepaymentEvaluationDate()
));
}
return summarizedProductForHoldingDtos;
}

public ResponseSingleProductDto findOne(Long id) {
log.info("Before retrieving the product data");
Product product = productRepository.findOne(id).orElseThrow(ProductNotFoundException::new);
Expand Down

0 comments on commit c091de7

Please sign in to comment.