Skip to content

Commit

Permalink
Merge pull request #61 from SWM-WeLike2Coding/dev
Browse files Browse the repository at this point in the history
conf: 개발 서버 배포를 위한 머지 작업
  • Loading branch information
kjungw1025 authored Sep 2, 2024
2 parents c091de7 + 609def8 commit 82b06d8
Show file tree
Hide file tree
Showing 12 changed files with 543 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
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;
import com.wl2c.elswhereproductservice.domain.product.model.dto.response.ResponseNextRepaymentEvaluationDateDto;
import com.wl2c.elswhereproductservice.domain.product.model.dto.response.ResponseProductComparisonTargetDto;
import com.wl2c.elswhereproductservice.domain.product.model.dto.response.ResponseSingleProductDto;
import com.wl2c.elswhereproductservice.domain.product.model.dto.response.*;
import com.wl2c.elswhereproductservice.domain.product.service.ProductEquityVolatilityService;
import com.wl2c.elswhereproductservice.domain.product.service.RepaymentEvaluationDatesService;
import com.wl2c.elswhereproductservice.domain.product.service.ProductService;
import com.wl2c.elswhereproductservice.global.model.dto.ResponsePage;
Expand All @@ -30,6 +28,7 @@ public class ProductController {

private final ProductService productService;
private final RepaymentEvaluationDatesService repaymentEvaluationDatesService;
private final ProductEquityVolatilityService productEquityVolatilityService;

/**
* 청약 중인 상품 목록
Expand Down Expand Up @@ -187,4 +186,15 @@ public ResponseNextRepaymentEvaluationDateDto findNextRepaymentEvaluationDate(@P
public ResponseMaturityRepaymentEvaluationDateDto findMaturityRepaymentEvaluationDate(@PathVariable Long id) {
return repaymentEvaluationDatesService.findMaturityRepaymentEvaluationDate(id);
}

/**
* 특정 상품의 기초자산별 변동성 조회
*
* @param id 상품 id
* @return 기초자산명 및 해당 각 기초자산에 대한 변동성 dto
*/
@GetMapping("/equity/volatility/{id}")
public ResponseProductEquityVolatilityDto findProductEquityVolatilities(@PathVariable Long id) {
return productEquityVolatilityService.findProductEquityVolatilities(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.wl2c.elswhereproductservice.domain.product.model.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Getter
public class ResponseProductEquityVolatilityDto {

@Schema(description = "기초자산명 리스트")
private final List<String> equityList;

@Schema(description = "각 기초자산 별 티커 정보")
private final Map<String, BigDecimal> equityVolatilities;

public ResponseProductEquityVolatilityDto(List<String> equityList,
Map<String, BigDecimal> equityVolatilities) {
this.equityList = equityList;
this.equityVolatilities = equityVolatilities;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.wl2c.elswhereproductservice.domain.product.repository;

import com.wl2c.elswhereproductservice.domain.product.model.entity.ProductEquityVolatility;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

public interface ProductEquityVolatilityRepository extends JpaRepository<ProductEquityVolatility, Long> {

@Query("select p from ProductEquityVolatility p " +
"where p.id in :productTickerSymbolIdList ")
List<ProductEquityVolatility> findAllByProductTickerSymbol(@RequestParam("productTickerSymbolIdList") List<Long> productTickerSymbolIdList);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

import com.wl2c.elswhereproductservice.domain.product.model.entity.ProductTickerSymbol;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

public interface ProductTickerSymbolRepository extends JpaRepository<ProductTickerSymbol, Long> {

@Query("select p from ProductTickerSymbol p " +
"where p.product.id = :productId ")
List<ProductTickerSymbol> findAllByProductId(@RequestParam("productId") Long productId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.wl2c.elswhereproductservice.domain.product.service;

import com.wl2c.elswhereproductservice.domain.product.exception.ProductNotFoundException;
import com.wl2c.elswhereproductservice.domain.product.model.dto.response.ResponseProductEquityVolatilityDto;
import com.wl2c.elswhereproductservice.domain.product.model.entity.ProductEquityVolatility;
import com.wl2c.elswhereproductservice.domain.product.model.entity.ProductTickerSymbol;
import com.wl2c.elswhereproductservice.domain.product.repository.ProductEquityVolatilityRepository;
import com.wl2c.elswhereproductservice.domain.product.repository.ProductRepository;
import com.wl2c.elswhereproductservice.domain.product.repository.ProductTickerSymbolRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@RequiredArgsConstructor
@Slf4j
public class ProductEquityVolatilityService {

private final ProductEquityVolatilityRepository productEquityVolatilityRepository;
private final ProductTickerSymbolRepository productTickerSymbolRepository;
private final ProductRepository productRepository;

public ResponseProductEquityVolatilityDto findProductEquityVolatilities(Long productId) {
if (productRepository.findOne(productId).isEmpty()) {
throw new ProductNotFoundException();
}

List<ProductTickerSymbol> productTickerSymbolList = productTickerSymbolRepository.findAllByProductId(productId);
List<Long> productTickerSymbolIdList = productTickerSymbolList.stream()
.map(ProductTickerSymbol::getId)
.toList();
List<String> equityList = productTickerSymbolList.stream()
.map(ProductTickerSymbol::getEquityName)
.toList();

List<ProductEquityVolatility> productEquityVolatilityList = productEquityVolatilityRepository.findAllByProductTickerSymbol(productTickerSymbolIdList);

Map<String, BigDecimal> result = new HashMap<>();
for (ProductTickerSymbol productTickerSymbol : productTickerSymbolList) {
for (ProductEquityVolatility productEquityVolatility : productEquityVolatilityList) {
if (productEquityVolatility.getId().equals(productTickerSymbol.getId()))
result.put(productTickerSymbol.getEquityName(), productEquityVolatility.getVolatility());
}
}

return new ResponseProductEquityVolatilityDto(equityList, result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.wl2c.elswhereproductservice.domain.product.repository;

import com.wl2c.elswhereproductservice.domain.product.model.MaturityEvaluationDateType;
import com.wl2c.elswhereproductservice.domain.product.model.ProductState;
import com.wl2c.elswhereproductservice.domain.product.model.ProductType;
import com.wl2c.elswhereproductservice.domain.product.model.UnderlyingAssetType;
import com.wl2c.elswhereproductservice.domain.product.model.entity.Product;
import com.wl2c.elswhereproductservice.domain.product.model.entity.ProductEquityVolatility;
import com.wl2c.elswhereproductservice.domain.product.model.entity.ProductTickerSymbol;
import com.wl2c.elswhereproductservice.domain.product.model.entity.TickerSymbol;
import com.wl2c.elswhereproductservice.mock.ProductEquityVolatilityMock;
import com.wl2c.elswhereproductservice.mock.ProductMock;
import com.wl2c.elswhereproductservice.mock.ProductTickerSymbolMock;
import com.wl2c.elswhereproductservice.mock.TickerSymbolMock;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

@DataJpaTest
public class ProductEquityVolatilityRepositoryTest {

@Autowired
private TickerSymbolRepository tickerSymbolRepository;

@Autowired
private ProductTickerSymbolRepository productTickerSymbolRepository;

@Autowired
private ProductRepository productRepository;

@Autowired
private ProductEquityVolatilityRepository productEquityVolatilityRepository;

List<ProductTickerSymbol> productTickerSymbolList;

@BeforeEach
void before() {
tickerSymbolRepository.deleteAll();
productTickerSymbolRepository.deleteAll();

List<TickerSymbol> tickerSymbols = Arrays.asList(
TickerSymbolMock.create("005930.KS", "삼성전자", UnderlyingAssetType.STOCK),
TickerSymbolMock.create("^GSPC", "S&P500", UnderlyingAssetType.INDEX),
TickerSymbolMock.create("^KS200", "KOSPI200", UnderlyingAssetType.INDEX)
);

Product product = ProductMock.create(
"AA증권",
"AA증권 1호",
"삼성전자 / S&P500 / KOSPI200",
3,
LocalDate.now().minusDays(1),
LocalDate.now().plusYears(3),
LocalDate.now().plusYears(3).minusDays(5),
MaturityEvaluationDateType.SINGLE,
new BigDecimal("10.423"),
LocalDate.now().minusDays(14),
LocalDate.now().minusDays(1),
"95-90-85-80-75-50",
45,
ProductType.STEP_DOWN,
ProductState.ACTIVE);

tickerSymbolRepository.saveAll(tickerSymbols);
productRepository.save(product);

productTickerSymbolList = ProductTickerSymbolMock.createList(product, Arrays.asList(
tickerSymbols.get(0),
tickerSymbols.get(1),
tickerSymbols.get(2)
));
productTickerSymbolRepository.saveAll(productTickerSymbolList);
}

@Test
@DisplayName("각 기초자산들의 변동성 값을 잘 가져오는지 확인")
void findAllByProductTickerSymbol() {
// given
List<Long> productTickerSymbolIdList = productTickerSymbolList.stream()
.map(ProductTickerSymbol::getId)
.toList();

List<BigDecimal> volatilityList = Arrays.asList(
BigDecimal.valueOf(13.3333),
BigDecimal.valueOf(53.244505),
BigDecimal.valueOf(70.98242)
);

List<ProductEquityVolatility> productEquityVolatilityList = ProductEquityVolatilityMock.createList(productTickerSymbolList, volatilityList);
productEquityVolatilityRepository.saveAll(productEquityVolatilityList);

// when
List<ProductEquityVolatility> responseProductEquityVolatilityList = productEquityVolatilityRepository.findAllByProductTickerSymbol(productTickerSymbolIdList);

// then
assertThat(responseProductEquityVolatilityList.size()).isEqualTo(3);
for (ProductEquityVolatility productEquityVolatility : responseProductEquityVolatilityList) {
for (int i = 0; i < productTickerSymbolList.size(); i++) {
if (productEquityVolatility.getProductTickerSymbol().equals(productTickerSymbolList.get(i)))
assertThat(productEquityVolatility.getVolatility()).isEqualTo(volatilityList.get(i));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.wl2c.elswhereproductservice.domain.product.repository;

import com.wl2c.elswhereproductservice.domain.product.model.MaturityEvaluationDateType;
import com.wl2c.elswhereproductservice.domain.product.model.ProductState;
import com.wl2c.elswhereproductservice.domain.product.model.ProductType;
import com.wl2c.elswhereproductservice.domain.product.model.UnderlyingAssetType;
import com.wl2c.elswhereproductservice.domain.product.model.entity.Product;
import com.wl2c.elswhereproductservice.domain.product.model.entity.ProductTickerSymbol;
import com.wl2c.elswhereproductservice.domain.product.model.entity.TickerSymbol;
import com.wl2c.elswhereproductservice.mock.ProductMock;
import com.wl2c.elswhereproductservice.mock.ProductTickerSymbolMock;
import com.wl2c.elswhereproductservice.mock.TickerSymbolMock;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

@DataJpaTest
public class ProductTickerSymbolRepositoryTest {

@Autowired
private TickerSymbolRepository tickerSymbolRepository;

@Autowired
private ProductRepository productRepository;

@Autowired
private ProductTickerSymbolRepository productTickerSymbolRepository;

Product product;

@BeforeEach
void before() {
tickerSymbolRepository.deleteAll();
productRepository.deleteAll();
productTickerSymbolRepository.deleteAll();

List<TickerSymbol> tickerSymbols = Arrays.asList(
TickerSymbolMock.create("005930.KS", "삼성전자", UnderlyingAssetType.STOCK),
TickerSymbolMock.create("^GSPC", "S&P500", UnderlyingAssetType.INDEX),
TickerSymbolMock.create("^KS200", "KOSPI200", UnderlyingAssetType.INDEX)
);

product = ProductMock.create(
"AA증권",
"AA증권 1호",
"삼성전자 / S&P500 / KOSPI200",
3,
LocalDate.now().minusDays(1),
LocalDate.now().plusYears(3),
LocalDate.now().plusYears(3).minusDays(5),
MaturityEvaluationDateType.SINGLE,
new BigDecimal("10.423"),
LocalDate.now().minusDays(14),
LocalDate.now().minusDays(1),
"95-90-85-80-75-50",
45,
ProductType.STEP_DOWN,
ProductState.ACTIVE);

tickerSymbolRepository.saveAll(tickerSymbols);
productRepository.save(product);

List<ProductTickerSymbol> productTickerSymbolList = ProductTickerSymbolMock.createList(product, Arrays.asList(
tickerSymbols.get(0),
tickerSymbols.get(1),
tickerSymbols.get(2)
));
productTickerSymbolRepository.saveAll(productTickerSymbolList);
}

@Test
@DisplayName("상품 id에 해당하는 티커 심볼들을 잘 가져오는지 확인")
void findAllByProductId() {
// when
List<ProductTickerSymbol> productTickerSymbolList = productTickerSymbolRepository.findAllByProductId(product.getId());

// then
for (ProductTickerSymbol productTickerSymbol : productTickerSymbolList) {
assertThat(productTickerSymbol.getProduct().getId()).isEqualTo(product.getId());
}
assertThat(productTickerSymbolList.size()).isEqualTo(3);
assertThat(productTickerSymbolList.get(0).getTickerSymbol().getTickerSymbol()).containsAnyOf("005930.KS", "^GSPC", "^KS200");
assertThat(productTickerSymbolList.get(1).getTickerSymbol().getTickerSymbol()).containsAnyOf("005930.KS", "^GSPC", "^KS200");
assertThat(productTickerSymbolList.get(2).getTickerSymbol().getTickerSymbol()).containsAnyOf("005930.KS", "^GSPC", "^KS200");
}
}
Loading

0 comments on commit 82b06d8

Please sign in to comment.