Skip to content

Commit

Permalink
agrego la promo
Browse files Browse the repository at this point in the history
  • Loading branch information
ignaciano3 committed Oct 22, 2023
1 parent e50204d commit b64a672
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/com/aninfo/model/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,12 @@ public ArrayList<Transaction> getTransactions() {
return transactions;
}

public Double getPromo() {
return promo;
}

public void setPromo(Double promo) {
this.promo = promo;
}

}
8 changes: 8 additions & 0 deletions src/main/java/com/aninfo/service/AccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public Account deposit(Long cbu, Double sum) {

account.setBalance(account.getBalance() + sum);
account.addTransaction(new Transaction(sum, TransactionType.DEPOSIT));

if (sum >= 2000 && account.getPromo() > 0){
Double promoApplied = Math.min(sum * 0.1, account.getPromo());
account.setBalance(account.getBalance() + promoApplied);
account.setPromo(account.getPromo() - promoApplied);
account.addTransaction(new Transaction(promoApplied, TransactionType.PROMO));
}

accountRepository.save(account);

return account;
Expand Down

0 comments on commit b64a672

Please sign in to comment.