Skip to content

Commit 125d75e

Browse files
committed
fix: balance not changing
1 parent 0ae7893 commit 125d75e

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/main/java/app/banking/services/TransferService.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,20 @@ public Object groupedTransfer(GroupTransferPayload payload){
160160
.amount(Math.abs(payload.getAmount()))
161161
.idAccount(transaction.getReceiver())
162162
.build());
163+
AccountBalance defaultBalance = new AccountBalance();
164+
defaultBalance.setCurrentBalance(0D);
165+
defaultBalance.setIdAccount(transaction.getReceiver());
163166
AccountBalance targetBalance = balanceRepo
164167
.findCurrentByAccountId(transaction.getReceiver().getId())
165-
.orElse(null);
166-
if(targetBalance != null){
167-
double amount = targetBalance.getCurrentBalance() + payload.getAmount();
168-
transactionService.deposit(DepositPayload
169-
.builder()
170-
.label(label)
171-
.accountId(transaction.getReceiver().getId())
172-
.amount(amount)
173-
.build());
174-
}
168+
.orElse(defaultBalance);
169+
System.out.println(transaction.getReceiver().getId());
170+
double amount = targetBalance.getCurrentBalance() + payload.getAmount();
171+
transactionService.deposit(DepositPayload
172+
.builder()
173+
.label(label)
174+
.accountId(transaction.getReceiver().getId())
175+
.amount(amount)
176+
.build());
175177
}
176178
AccountBalance accountBalance = new AccountBalance();
177179
accountBalance.setIdAccount(transactionGroup.getIdAccount());

0 commit comments

Comments
 (0)