주문시 checkStock 를 체크하도록 변경함

This commit is contained in:
kimscott
2019-09-27 14:16:23 +09:00
parent fffc3e0f8a
commit 2eb86b2fe2
2 changed files with 15 additions and 9 deletions

View File

@@ -46,18 +46,20 @@ public class Order {
throw new RuntimeException();
}
// 1. 주문에 대한 상품 조회 - API
String productUrl = env.getProperty("productUrl") + "/products/" + productId;
if("true".equalsIgnoreCase(env.getProperty("checkStock"))){
// 1. 주문에 대한 상품 조회 - API
String productUrl = env.getProperty("productUrl") + "/products/" + productId;
ResponseEntity<String> productEntity = restTemplate.getForEntity(productUrl, String.class);
JsonParser parser = new JsonParser();
JsonObject jsonObject = parser.parse(productEntity.getBody()).getAsJsonObject();
ResponseEntity<String> productEntity = restTemplate.getForEntity(productUrl, String.class);
JsonParser parser = new JsonParser();
JsonObject jsonObject = parser.parse(productEntity.getBody()).getAsJsonObject();
this.setPrice(jsonObject.get("price").getAsInt());
this.setProductName(jsonObject.get("name").getAsString());
this.setPrice(jsonObject.get("price").getAsInt());
this.setProductName(jsonObject.get("name").getAsString());
if( jsonObject.get("stock").getAsInt() < getQuantity()){
throw new RuntimeException("No Available stock!");
if( jsonObject.get("stock").getAsInt() < getQuantity()){
throw new RuntimeException("No Available stock!");
}
}
OrderPlaced orderPlaced = new OrderPlaced();

View File

@@ -3,6 +3,10 @@ server:
eventTopic: eventTopic
## 주문은 product 정보가 필요하다.
## checkStock 를 true 로 준다면, product 서비스가 죽어있을때는 주문이 안된다.
checkStock: false
---
spring:
profiles: default