-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from SWM-WeLike2Coding/dev
conf: 개발 서버 배포를 위한 머지 작업
- Loading branch information
Showing
12 changed files
with
543 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...eproductservice/domain/product/model/dto/response/ResponseProductEquityVolatilityDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...c/elswhereproductservice/domain/product/repository/ProductEquityVolatilityRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...om/wl2c/elswhereproductservice/domain/product/service/ProductEquityVolatilityService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
...swhereproductservice/domain/product/repository/ProductEquityVolatilityRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
...c/elswhereproductservice/domain/product/repository/ProductTickerSymbolRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
Oops, something went wrong.