From 41c839a0305701f4a463116fdc8a83f04dd323d7 Mon Sep 17 00:00:00 2001 From: Luis Ferreira Pires <l.ferreirapires@utwente.nl> Date: Sun, 28 Feb 2021 12:35:44 +0100 Subject: [PATCH] Modified application to set the number of elements to be purchased (to make service more interesting). --- .gitignore | 2 + spring-shell.log | 17 ++++++++ .../commands/InventoryCommands.java | 40 ++++++++----------- .../services/InventoryService.java | 4 +- 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 6c01878..0d05153 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ out/ ### VS Code ### .vscode/ +.DS_Store +bin diff --git a/spring-shell.log b/spring-shell.log index 9ddac45..f799e82 100644 --- a/spring-shell.log +++ b/spring-shell.log @@ -1,2 +1,19 @@ 1614157428833:current 1614157453899:exit +1614511411899:current +1614511421913:purchase +1614511428936:sell 50 +1614511431942:current +1614511701060:purchase +1614511706073:purchase 20 +1614511711082:sell +1614511716096:sell 200 +1614511723110:current +1614511728131:sell 120 +1614511733140:sell 20 +1614511739156:current +1614511848909:purchase 10 +1614511852915:current +1614511857930:sell 110 +1614511874976:sell 105 +1614511880024:current diff --git a/src/main/java/nl/utwente/soa/inventoryApplication/commands/InventoryCommands.java b/src/main/java/nl/utwente/soa/inventoryApplication/commands/InventoryCommands.java index 2a32921..64d8b49 100644 --- a/src/main/java/nl/utwente/soa/inventoryApplication/commands/InventoryCommands.java +++ b/src/main/java/nl/utwente/soa/inventoryApplication/commands/InventoryCommands.java @@ -9,32 +9,26 @@ import org.springframework.shell.standard.ShellMethod; @ShellComponent public class InventoryCommands { - @Autowired private InventoryService inventoryService; + @Autowired + private InventoryService inventoryService; - @ShellMethod("Sell inventory") - public String sell( - int amount - ) { - inventoryService.subtractInventory(amount); - return "Sold inventory"; - } + @ShellMethod("Sell inventory") + public String sell(int amount) { + inventoryService.subtractInventory(amount); + return "Sold inventory"; + } - @ShellMethod("Buy new inventory") - public String purchase() { + @ShellMethod("Buy new inventory") + public String purchase(int amount) { - // Do a request to the Purchase service - - inventoryService.addInventory(50); - - return "Jeej new inventory"; - } - - @ShellMethod("Get Current inventory") - public String current(){ - - return "Current inventory: " + inventoryService.getCurrentInventory(); - - } + // Request to the Purchase service should be done here!!! + inventoryService.addInventory(amount); + return "More " + amount + " items in the inventory"; + } + @ShellMethod("Get Current inventory") + public String current() { + return "Current inventory: " + inventoryService.getCurrentInventory(); + } } diff --git a/src/main/java/nl/utwente/soa/inventoryApplication/services/InventoryService.java b/src/main/java/nl/utwente/soa/inventoryApplication/services/InventoryService.java index 323b80c..47155fb 100644 --- a/src/main/java/nl/utwente/soa/inventoryApplication/services/InventoryService.java +++ b/src/main/java/nl/utwente/soa/inventoryApplication/services/InventoryService.java @@ -12,8 +12,8 @@ public class InventoryService { return InventoryService.currentInventory; } - public void addInventory(int ammount){ - InventoryService.currentInventory += currentInventory; + public void addInventory(int amount){ + InventoryService.currentInventory += amount; } public void subtractInventory(int amount){ -- GitLab