public void withdrawAmount(String name, long amount) throws AmountExceedsAccountBalanceException { Account account = accountRepository.findOne(name); Long newBalance = account.getBalance() - amount; if (newBalance < 0) { throw new AmountExceedsAccountBalanceException("You Can't Exceed Your Current Balance"); } else { account.setBalance(newBalance); accountRepository.save(account); transactionService.createTransaction(name, "Withdraw", "", amount, account.getBalance()); } }
public void depositAmount(String name, long amount) { Account account = accountRepository.findOne(name); account.setBalance(account.getBalance() + amount); accountRepository.save(account); transactionService.createTransaction(name, "Deposit", "", amount, account.getBalance()); }