주문시 checkStock 를 체크하도록 변경함
This commit is contained in:
@@ -46,18 +46,20 @@ public class Order {
|
|||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. 주문에 대한 상품 조회 - API
|
if("true".equalsIgnoreCase(env.getProperty("checkStock"))){
|
||||||
String productUrl = env.getProperty("productUrl") + "/products/" + productId;
|
// 1. 주문에 대한 상품 조회 - API
|
||||||
|
String productUrl = env.getProperty("productUrl") + "/products/" + productId;
|
||||||
|
|
||||||
ResponseEntity<String> productEntity = restTemplate.getForEntity(productUrl, String.class);
|
ResponseEntity<String> productEntity = restTemplate.getForEntity(productUrl, String.class);
|
||||||
JsonParser parser = new JsonParser();
|
JsonParser parser = new JsonParser();
|
||||||
JsonObject jsonObject = parser.parse(productEntity.getBody()).getAsJsonObject();
|
JsonObject jsonObject = parser.parse(productEntity.getBody()).getAsJsonObject();
|
||||||
|
|
||||||
this.setPrice(jsonObject.get("price").getAsInt());
|
this.setPrice(jsonObject.get("price").getAsInt());
|
||||||
this.setProductName(jsonObject.get("name").getAsString());
|
this.setProductName(jsonObject.get("name").getAsString());
|
||||||
|
|
||||||
if( jsonObject.get("stock").getAsInt() < getQuantity()){
|
if( jsonObject.get("stock").getAsInt() < getQuantity()){
|
||||||
throw new RuntimeException("No Available stock!");
|
throw new RuntimeException("No Available stock!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OrderPlaced orderPlaced = new OrderPlaced();
|
OrderPlaced orderPlaced = new OrderPlaced();
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ server:
|
|||||||
|
|
||||||
|
|
||||||
eventTopic: eventTopic
|
eventTopic: eventTopic
|
||||||
|
|
||||||
|
## 주문은 product 정보가 필요하다.
|
||||||
|
## checkStock 를 true 로 준다면, product 서비스가 죽어있을때는 주문이 안된다.
|
||||||
|
checkStock: false
|
||||||
---
|
---
|
||||||
spring:
|
spring:
|
||||||
profiles: default
|
profiles: default
|
||||||
|
|||||||
Reference in New Issue
Block a user