Skip to content
Snippets Groups Projects
Commit e016103c authored by roxanne.grant's avatar roxanne.grant
Browse files

Error resolved : Credit an account that doesn't exist and stock a product that doesn't exist

parent 01da8b70
No related branches found
No related tags found
No related merge requests found
......@@ -84,8 +84,13 @@ public class AccountService{
//------------------------------------------
if (obj instanceof EventCreditAnAccount){
EventCreditAnAccount e = (EventCreditAnAccount) obj;
accountsDB.creditAnAccount(e.idAccount(), e.amount());
send(new EventAccountCredited(e.id(), "The account is credited"));
if(accountsDB.accountPresent(e.idAccount())){
accountsDB.creditAnAccount(e.idAccount(), e.amount());
send(new EventAccountCredited(e.id(), "The account is credited"));
}
else{
send(new EventAccountDoesntExist(e.id(), "The account doesn't exist"));
}
System.out.println(e.toString());
}
//------------------------------------------
......
......@@ -89,8 +89,14 @@ public class StockService {
// ------------------------------------------
if (obj instanceof EventAddProductQuantity) {
EventAddProductQuantity e = (EventAddProductQuantity) obj;
stockDB.addQuantity(e.idProduct(), e.quantity());
send(new EventProductQuantityAdded(e.id(), "Quantity added to the stock"));
if(productsDB.getById(e.idProduct()).isPresent()){
stockDB.addQuantity(e.idProduct(), e.quantity());
send(new EventProductQuantityAdded(e.id(), "Quantity added to the stock"));
}
else{
send(new EventProductDoesntExist(e.id(), "Product doesn't exist"));
}
System.out.println(e.toString());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment