diff --git a/services/src/main/java/ch/hepia/order/http.java b/services/src/main/java/ch/hepia/order/http.java index 844e1186f535f21af735df2107128c7049bc1ce9..52188622dfa91d451c18a92ba759a41ae4f0a351 100644 --- a/services/src/main/java/ch/hepia/order/http.java +++ b/services/src/main/java/ch/hepia/order/http.java @@ -19,22 +19,27 @@ public class http { private static OrderService orderService; private static AccountService accountService; private static StockService stockService; + private static int idService; public static void main(String[] args) { http.orderService = new OrderService("localhost"); http.accountService = new AccountService("localhost"); http.stockService = new StockService("localhost"); + http.idService = 0; SpringApplication.run(http.class, args); } + public static int getId() { return http.idService; } + public static void incrementId() { http.idService++; } + @RequestMapping("/order") public Order order( @RequestParam(value = "idAccount", defaultValue = "1") int idAccount, @RequestParam(value = "idProduct", defaultValue = "1") int idProduct, @RequestParam(value = "quantity", defaultValue = "1") int quantity ) { - int idOrder = 5; - Order o = new Order(idOrder, idAccount); + http.incrementId(); + Order o = new Order(http.getId(), idAccount); o.addProduct(idProduct, quantity); Event oc = new EventOrderCreated(o.id(), "hello", idAccount, o.getProducts()); @@ -45,8 +50,8 @@ public class http { @RequestMapping("/orderNotExistingProducts") public Order orderNotExistingProducts() { int idAccount = 1; - int idOrder = 5; - Order o = new Order(idOrder, idAccount); + http.incrementId(); + Order o = new Order(http.getId(), idAccount); o.addProduct(1, 4); o.addProduct(999, 4); Event oc = new EventOrderCreated(o.id(), "hello", idAccount, o.getProducts()); @@ -56,7 +61,8 @@ public class http { @RequestMapping("/createAccount") public String createAccount(@RequestParam(value = "name", defaultValue = "Orphée") String name) { - accountService.send(new EventCreateAccount(1, "Creating the account", name)); + http.incrementId(); + accountService.send(new EventCreateAccount(http.getId(), "Creating the account", name)); return name; } @@ -64,16 +70,17 @@ public class http { public String createAccount( @RequestParam(value = "idAccount", defaultValue = "1") int idAccount, @RequestParam(value = "amount", defaultValue = "1") double amount) { - accountService.send(new EventCreditAnAccount(5, "Crediting account", idAccount, amount)); + http.incrementId(); + accountService.send(new EventCreditAnAccount(http.getId(), "Crediting account", idAccount, amount)); return null; } @RequestMapping("/createProduct") public Product createProduct(@RequestParam(value = "name", defaultValue = "poire") String name, - @RequestParam(value = "price", defaultValue = "1") double price) { - - stockService.send(new EventCreateProduct(1, "Creating the product", name, price)); + @RequestParam(value = "price", defaultValue = "1") double price) { + http.incrementId(); + stockService.send(new EventCreateProduct(http.getId(), "Creating the product", name, price)); return null; }