diff --git a/services/src/main/java/ch/hepia/order/http.java b/services/src/main/java/ch/hepia/order/http.java index 52188622dfa91d451c18a92ba759a41ae4f0a351..7420d904d1a62b7725eba5fe5a6ff02a4f24abe2 100644 --- a/services/src/main/java/ch/hepia/order/http.java +++ b/services/src/main/java/ch/hepia/order/http.java @@ -77,11 +77,20 @@ public class http { @RequestMapping("/createProduct") - public Product createProduct(@RequestParam(value = "name", defaultValue = "poire") String name, + public Product createProduct( + @RequestParam(value = "name", defaultValue = "poire") String name, @RequestParam(value = "price", defaultValue = "1") double price) { http.incrementId(); stockService.send(new EventCreateProduct(http.getId(), "Creating the product", name, price)); + return null; + } + @RequestMapping("/supplyStock") + public Product supplyStock( + @RequestParam(value = "idProduct", defaultValue = "1") int idProduct, + @RequestParam(value = "quantity", defaultValue = "10") int quantity) { + http.incrementId(); + stockService.send(new EventAddProductQuantity(http.getId(), "Supplying ", idProduct, quantity)); return null; } diff --git a/services/src/main/java/ch/hepia/stock/StockService.java b/services/src/main/java/ch/hepia/stock/StockService.java index 41c34bef8babac395afe421f056d5913f9bf6873..ab32d84e881fa1d59ed78e065fce08e63bdf0588 100644 --- a/services/src/main/java/ch/hepia/stock/StockService.java +++ b/services/src/main/java/ch/hepia/stock/StockService.java @@ -93,6 +93,12 @@ public class StockService { send(new EventProductQuantityAdded(e.id(), "Quantity added to the stock")); System.out.println(e.toString()); } + + if(obj instanceof EventProductQuantityAdded){ + EventProductQuantityAdded e = (EventProductQuantityAdded) obj; + System.out.println(e.toString()); + } + // ------------------------------------------ if (obj instanceof EventOrderCreated) { EventOrderCreated e = (EventOrderCreated) obj; diff --git a/services/src/main/resources/static/demo.html b/services/src/main/resources/static/demo.html index c5b8611deb9bad317c3d074c06e243884c1f94e1..db7f81c5658aff5a498205ff2f924595c0b3aaa0 100644 --- a/services/src/main/resources/static/demo.html +++ b/services/src/main/resources/static/demo.html @@ -14,14 +14,18 @@ <hr> <h2>Products</h2> - <p>Create a product with default values <a href="/createProduct">/createProduct</a></p> - <p>Create a product that is an apple that costs 1.3 <a href="/createProduct?name=apple&price=1.3">/createProduct?name=apple&price=1.3</a></p> + <p>DEFAULT: Create a product with default values (name = poire) <a href="/createProduct">/createProduct</a></p> + <p>GET: Create a product that is an apple that costs 1.3 <a href="/createProduct?name=apple&price=1.3">/createProduct?name=apple&price=1.3</a></p> <h2>Accounts</h2> - <p>Create an account with default value (name=Orphée) <a href="/createAccount">/createAccount</a></p> - <p>Create an account with name Ovide <a href="/createAccount?name=Ovide">/createAccount?name=Ovide</a></p> + <p>DEFAULT: Create an account with default value (name = Orphée) <a href="/createAccount">/createAccount</a></p> + <p>GET: Create an account with name Ovide <a href="/createAccount?name=Ovide">/createAccount?name=Ovide</a></p> <p>Credit 50.- to account with id 1 <a href="/creditAccount?idAccount=1&amount=50">/creditAccount?idAccount=1&amount=50</a></p> + <h2>Stock</h2> + <p>DEFAULT: Supply with default values (idProduct = 1, quantity = 50) <a href="/supplyStock">/supplyStock</a></p> + <p>GET: Supply with desired values <a href="/supplyStock?idProduct=1&quantity=30">/supplyStock?idProduct=1&quantity=30</a></p> + <h2>Orders</h2> <!-- <p>Order 2 units of product with id = 1 <a href="/order?idProduct=1&quantity=2">/order?idProduct=1&quantity=2</a></p> --> <p>Demo 0: order 2 units of product with id = 1 <a href="/order?idProduct=1&quantity=2">/order?idProduct=1&quantity=2</a></p>