Skip to content

Commit

Permalink
Fixed balance history bug to allow months with no transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
ystxn committed Nov 29, 2024
1 parent 4b68d11 commit 0133865
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/main/java/tech/sledger/endpoints/DashEndpoints.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -154,13 +153,10 @@ public ChartResponse getBalanceHistory(Authentication auth) {
var accountSeries = accountIds.stream().map(accountId -> {
AtomicInteger monthIndex = new AtomicInteger();
List<BigDecimal> data = months.stream()
.map(month -> {
Optional<MonthlyBalance> value = balanceHistory.stream()
.filter(b -> b.getAccountId() == accountId && b.getMonth().equals(month))
.findFirst();
return value.get();
})
.map(MonthlyBalance::getBalance)
.map(month -> balanceHistory.stream()
.filter(b -> b.getAccountId() == accountId && b.getMonth().equals(month))
.findFirst()
.map(MonthlyBalance::getBalance).orElse(BigDecimal.ZERO))
.peek(balance -> {
if (summaryData.size() < months.size()) {
summaryData.add(balance);
Expand Down

0 comments on commit 0133865

Please sign in to comment.