From aae8bbb44e5869921b2c8710def502fd2a5186a3 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Sun, 23 Jan 2022 22:23:30 +0000 Subject: [PATCH] Return JSON and move /budget/:budgetid to API endpoint --- http/budgeting.go | 2 +- http/http.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/http/budgeting.go b/http/budgeting.go index 4bbb127..a45742d 100644 --- a/http/budgeting.go +++ b/http/budgeting.go @@ -116,7 +116,7 @@ func (h *Handler) budgeting(c *gin.Context) { d.AvailableBalance = availableBalance - c.HTML(http.StatusOK, "budgeting.html", d) + c.JSON(http.StatusOK, d) } func (h *Handler) calculateBalances(c *gin.Context, budget postgres.Budget, firstOfNextMonth time.Time, firstOfMonth time.Time, categories []postgres.GetCategoriesRow, cumultativeBalances []postgres.GetCumultativeBalancesRow) ([]CategoryWithBalance, float64, error) { diff --git a/http/http.go b/http/http.go index e492559..d1bb799 100644 --- a/http/http.go +++ b/http/http.go @@ -52,9 +52,8 @@ func (h *Handler) Serve() { withLogin.GET("/admin/clear-database", h.clearDatabase) withBudget := router.Group("") - withBudget.Use(h.verifyLoginWithRedirect) + withBudget.Use(h.verifyLoginWithForbidden) withBudget.Use(h.getImportantData) - withBudget.GET("/budget/:budgetid", h.budgeting) withBudget.GET("/budget/:budgetid/:year/:month", h.budgeting) withBudget.GET("/budget/:budgetid/all-accounts", h.allAccounts) withBudget.GET("/budget/:budgetid/accounts", h.accounts) @@ -75,6 +74,10 @@ func (h *Handler) Serve() { authenticated.Use(h.verifyLoginWithForbidden) authenticated.GET("/dashboard", h.dashboard) + withBudget2 := authenticated.Group("") + withBudget2.Use(h.getImportantData) + withBudget2.GET("/budget/:budgetid", h.budgeting) + budget := authenticated.Group("/budget") budget.POST("/new", h.newBudget)