diff --git a/ProductService/README.md b/ProductService/README.md index 3974b51..b4ce92f 100644 --- a/ProductService/README.md +++ b/ProductService/README.md @@ -13,8 +13,6 @@ create table t_product constraint t_product_pk primary key (id) ); - - ``` ## Libraries diff --git a/ProductService/src/main/java/com/redhat/sample/ecommerce/product/domain/Product.java b/ProductService/src/main/java/com/redhat/sample/ecommerce/product/domain/Product.java index 9df4fec..fb50bb7 100644 --- a/ProductService/src/main/java/com/redhat/sample/ecommerce/product/domain/Product.java +++ b/ProductService/src/main/java/com/redhat/sample/ecommerce/product/domain/Product.java @@ -24,6 +24,9 @@ public class Product implements Serializable { private String productImage; private BigDecimal productPrice; + @Transient + private Long stock; + public Product() { } @@ -75,4 +78,12 @@ public BigDecimal getProductPrice() { public void setProductPrice(BigDecimal productPrice) { this.productPrice = productPrice; } + + public Long getStock() { + return stock; + } + + public void setStock(Long stock) { + this.stock = stock; + } } diff --git a/ProductService/src/main/java/com/redhat/sample/ecommerce/product/helper/StockHelper.java b/ProductService/src/main/java/com/redhat/sample/ecommerce/product/helper/StockHelper.java new file mode 100644 index 0000000..95ef486 --- /dev/null +++ b/ProductService/src/main/java/com/redhat/sample/ecommerce/product/helper/StockHelper.java @@ -0,0 +1,22 @@ +package com.redhat.sample.ecommerce.product.helper; + +import com.redhat.sample.ecommerce.product.domain.Product; +import org.apache.camel.Body; +import org.apache.camel.Header; +import org.springframework.context.annotation.Bean; + +/** + *
+ *     com.redhat.sample.ecommerce.product.helper.StockHelper
+ * 
+ * + * @author Muhammad Edwin < edwin at redhat dot com > + * 07 Jun 2022 15:35 + */ +public class StockHelper { + @Bean + public Product addStockToProduct(@Body Product product, @Header("stock") String stock) { + product.setStock(Long.parseLong(stock)); + return product; + } +} diff --git a/ProductService/src/main/java/com/redhat/sample/ecommerce/product/route/ProductRoute.java b/ProductService/src/main/java/com/redhat/sample/ecommerce/product/route/ProductRoute.java index 99eb512..4674545 100644 --- a/ProductService/src/main/java/com/redhat/sample/ecommerce/product/route/ProductRoute.java +++ b/ProductService/src/main/java/com/redhat/sample/ecommerce/product/route/ProductRoute.java @@ -1,5 +1,6 @@ package com.redhat.sample.ecommerce.product.route; +import com.redhat.sample.ecommerce.product.helper.StockHelper; import com.redhat.sample.ecommerce.product.service.ProductService; import org.apache.camel.builder.RouteBuilder; import org.springframework.beans.factory.annotation.Autowired; @@ -39,6 +40,8 @@ public void configure() throws Exception { Long id = (Long) exchange.getIn().getBody(); exchange.getMessage().setBody(productService.getProduct(id)); }) + .setHeader("stock", simple("1")) + .bean(StockHelper.class, "addStockToProduct") .end(); } }