diff --git a/server/budgeting.go b/server/budgeting.go index 0645b2b..df43ca7 100644 --- a/server/budgeting.go +++ b/server/budgeting.go @@ -30,6 +30,16 @@ type CategoryWithBalance struct { Assigned postgres.Numeric } +func NewCategoryWithBalance(category *postgres.GetCategoriesRow) CategoryWithBalance { + return CategoryWithBalance{ + GetCategoriesRow: category, + Available: postgres.NewZeroNumeric(), + AvailableLastMonth: postgres.NewZeroNumeric(), + Activity: postgres.NewZeroNumeric(), + Assigned: postgres.NewZeroNumeric(), + } +} + func getDate(c *gin.Context) (time.Time, error) { var year, month int yearString := c.Param("year") @@ -153,16 +163,10 @@ func (h *Handler) calculateBalances(budget postgres.Budget, firstOfNextMonth time.Time, firstOfMonth time.Time, categories []postgres.GetCategoriesRow, cumultativeBalances []postgres.GetCumultativeBalancesRow) ([]CategoryWithBalance, postgres.Numeric) { categoriesWithBalance := []CategoryWithBalance{} - hiddenCategory := CategoryWithBalance{ - GetCategoriesRow: &postgres.GetCategoriesRow{ - Name: "", - Group: "Hidden Categories", - }, - Available: postgres.NewZeroNumeric(), - AvailableLastMonth: postgres.NewZeroNumeric(), - Activity: postgres.NewZeroNumeric(), - Assigned: postgres.NewZeroNumeric(), - } + hiddenCategory := NewCategoryWithBalance(&postgres.GetCategoriesRow{ + Name: "", + Group: "Hidden Categories", + }) moneyUsed := postgres.NewZeroNumeric() for i := range categories { @@ -194,13 +198,7 @@ func (*Handler) CalculateCategoryBalances(cat *postgres.GetCategoriesRow, cumultativeBalances []postgres.GetCumultativeBalancesRow, firstOfNextMonth time.Time, moneyUsed *postgres.Numeric, firstOfMonth time.Time, hiddenCategory CategoryWithBalance, budget postgres.Budget) CategoryWithBalance { - categoryWithBalance := CategoryWithBalance{ - GetCategoriesRow: cat, - Available: postgres.NewZeroNumeric(), - AvailableLastMonth: postgres.NewZeroNumeric(), - Activity: postgres.NewZeroNumeric(), - Assigned: postgres.NewZeroNumeric(), - } + categoryWithBalance := NewCategoryWithBalance(cat) for _, bal := range cumultativeBalances { if bal.CategoryID != cat.ID { continue