Skip to content
Snippets Groups Projects
Commit 00a083d2 authored by roxanne.grant's avatar roxanne.grant
Browse files
parents 5957a479 5d020260
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,7 @@ public class AccountDatabase {
}
public void creditAnAccount(int idAccount, double amount){
this.database.get(this.database.indexOf(getById(idAccount))).addAmount(amount);
this.database.get(this.database.indexOf(getById(idAccount).get())).addAmount(amount);
}
public boolean hasEnoughMoney(int idAccount, double price){
......@@ -37,6 +37,7 @@ public class AccountDatabase {
}
public void withdrawCreditAccount(int idAccount, double credit){
this.database.get(this.database.indexOf(getById(idAccount))).withdraw(credit);
System.out.println("ID:" + idAccount);
this.database.get(this.database.indexOf(getById(idAccount).get())).withdraw(credit);
}
}
\ No newline at end of file
......@@ -60,6 +60,15 @@ public class http {
return name;
}
@RequestMapping("/creditAccount")
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));
return null;
}
@RequestMapping("/createProduct")
public Product createProduct(@RequestParam(value = "name", defaultValue = "poire") String name,
@RequestParam(value = "price", defaultValue = "1") double price) {
......
......@@ -26,7 +26,7 @@ public class StockDatabase {
private boolean isProductsAvailable(Map<Integer, Integer> productsToVerify){
return productsToVerify.keySet()
.stream()
.anyMatch(p -> productsToVerify.get(p) > getQuantity(p));
.allMatch(idProduct -> this.getQuantity(idProduct) >= productsToVerify.get(idProduct) );
}
public double getTotalPrice(Map<Integer, Integer> productsToVerify, ProductDatabase pdb){
......
......@@ -18,8 +18,9 @@
<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>
<h2>Accounts</h2>
<p>Create an account with default values <a href="/createAccount">/createAccount</a></p>
<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>Credit 50.- to account with id 1 <a href="/creditAccount?idAccount=1&amount=50">/creditAccount?idAccount=1&amount=50</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> -->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment