diff --git a/src/main/java/com/example/template/Order.java b/src/main/java/com/example/template/Order.java index 37fe38b..764044e 100644 --- a/src/main/java/com/example/template/Order.java +++ b/src/main/java/com/example/template/Order.java @@ -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 productEntity = restTemplate.getForEntity(productUrl, String.class); - JsonParser parser = new JsonParser(); - JsonObject jsonObject = parser.parse(productEntity.getBody()).getAsJsonObject(); + ResponseEntity 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(); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index cb54b03..b1ab783 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -3,6 +3,10 @@ server: eventTopic: eventTopic + +## 주문은 product 정보가 필요하다. +## checkStock 를 true 로 준다면, product 서비스가 죽어있을때는 주문이 안된다. +checkStock: false --- spring: profiles: default