From b64a672b95a0c84b3542f203cc05f2bc39f96ffa Mon Sep 17 00:00:00 2001 From: ignaciano3 <57163642+ignaciano3@users.noreply.github.com> Date: Sun, 22 Oct 2023 20:55:05 +0000 Subject: [PATCH] agrego la promo --- src/main/java/com/aninfo/model/Account.java | 8 ++++++++ src/main/java/com/aninfo/service/AccountService.java | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/com/aninfo/model/Account.java b/src/main/java/com/aninfo/model/Account.java index e9e683bc..248c4309 100644 --- a/src/main/java/com/aninfo/model/Account.java +++ b/src/main/java/com/aninfo/model/Account.java @@ -59,4 +59,12 @@ public ArrayList getTransactions() { return transactions; } + public Double getPromo() { + return promo; + } + + public void setPromo(Double promo) { + this.promo = promo; + } + } diff --git a/src/main/java/com/aninfo/service/AccountService.java b/src/main/java/com/aninfo/service/AccountService.java index 12846a3d..3ff22524 100644 --- a/src/main/java/com/aninfo/service/AccountService.java +++ b/src/main/java/com/aninfo/service/AccountService.java @@ -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;