Skip to content

Commit

Permalink
adding stock field in json 🐘
Browse files Browse the repository at this point in the history
  • Loading branch information
edwin committed Jun 7, 2022
1 parent 2a4712b commit 570ecbd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 0 additions & 2 deletions ProductService/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ create table t_product
constraint t_product_pk
primary key (id)
);


```

## Libraries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class Product implements Serializable {
private String productImage;
private BigDecimal productPrice;

@Transient
private Long stock;

public Product() {
}

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;

/**
* <pre>
* com.redhat.sample.ecommerce.product.helper.StockHelper
* </pre>
*
* @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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 570ecbd

Please sign in to comment.