From 115264ce137d8357f4c934c6aa112a81a2f6b542 Mon Sep 17 00:00:00 2001
From: "roxanne.grant" <roxanne.grant@etu.hesge.ch>
Date: Sun, 3 Feb 2019 21:00:11 +0100
Subject: [PATCH] created an idService in class http to increment id at each
 new scenario

---
 .../src/main/java/ch/hepia/order/http.java    | 25 ++++++++++++-------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/services/src/main/java/ch/hepia/order/http.java b/services/src/main/java/ch/hepia/order/http.java
index 844e118..5218862 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;
     }
-- 
GitLab