Split displayed accounts by on- or off-budget

This commit is contained in:
2021-12-07 21:07:09 +00:00
parent 04fd687324
commit f4ddf12214
4 changed files with 41 additions and 14 deletions

View File

@ -9,8 +9,10 @@ import (
)
type AlwaysNeededData struct {
Budget postgres.Budget
Accounts []postgres.GetAccountsWithBalanceRow
Budget postgres.Budget
Accounts []postgres.GetAccountsWithBalanceRow
OnBudgetAccounts []postgres.GetAccountsWithBalanceRow
OffBudgetAccounts []postgres.GetAccountsWithBalanceRow
}
func (h *Handler) getImportantData(c *gin.Context) {
@ -34,9 +36,20 @@ func (h *Handler) getImportantData(c *gin.Context) {
return
}
var onBudgetAccounts, offBudgetAccounts []postgres.GetAccountsWithBalanceRow
for _, account := range accounts {
if account.OnBudget {
onBudgetAccounts = append(onBudgetAccounts, account)
} else {
offBudgetAccounts = append(offBudgetAccounts, account)
}
}
base := AlwaysNeededData{
Accounts: accounts,
Budget: budget,
Accounts: accounts,
OnBudgetAccounts: onBudgetAccounts,
OffBudgetAccounts: offBudgetAccounts,
Budget: budget,
}
c.Set("data", base)