From 52bb343402a81e465ac7efc39bfbd93e8deb1f5e Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Fri, 25 Feb 2022 22:52:08 +0000 Subject: [PATCH] Reorganize routes and remove legacy ones --- server/http.go | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/server/http.go b/server/http.go index 74e1fad..80e9bd4 100644 --- a/server/http.go +++ b/server/http.go @@ -41,20 +41,12 @@ func (h *Handler) LoadRoutes(router *gin.Engine) { router.Use(enableCachingForStaticFiles()) router.NoRoute(h.ServeStatic) - withLogin := router.Group("") - withLogin.Use(h.verifyLoginWithRedirect) - - withBudget := router.Group("") - withBudget.Use(h.verifyLoginWithForbidden) - withBudget.GET("/budget/:budgetid/:year/:month", h.budgeting) - withBudget.GET("/budget/:budgetid/settings/clean-negative", h.cleanNegativeBudget) - api := router.Group("/api/v1") - unauthenticated := api.Group("/user") - unauthenticated.GET("/login", func(c *gin.Context) { c.Redirect(http.StatusPermanentRedirect, "/login") }) - unauthenticated.POST("/login", h.loginPost) - unauthenticated.POST("/register", h.registerPost) + anonymous := api.Group("/user") + anonymous.GET("/login", func(c *gin.Context) { c.Redirect(http.StatusPermanentRedirect, "/login") }) + anonymous.POST("/login", h.loginPost) + anonymous.POST("/register", h.registerPost) authenticated := api.Group("") authenticated.Use(h.verifyLoginWithForbidden) @@ -62,18 +54,19 @@ func (h *Handler) LoadRoutes(router *gin.Engine) { authenticated.GET("/account/:accountid/transactions", h.transactionsForAccount) authenticated.POST("/account/:accountid", h.editAccount) authenticated.GET("/admin/clear-database", h.clearDatabase) - authenticated.GET("/budget/:budgetid", h.budgeting) - authenticated.GET("/budget/:budgetid/:year/:month", h.budgetingForMonth) - authenticated.GET("/budget/:budgetid/autocomplete/payees", h.autocompletePayee) - authenticated.GET("/budget/:budgetid/autocomplete/categories", h.autocompleteCategories) - authenticated.DELETE("/budget/:budgetid", h.deleteBudget) - authenticated.POST("/budget/:budgetid/import/ynab", h.importYNAB) - authenticated.POST("/budget/:budgetid/export/ynab/transactions", h.exportYNABTransactions) - authenticated.POST("/budget/:budgetid/export/ynab/assignments", h.exportYNABAssignments) - authenticated.POST("/budget/:budgetid/settings/clear", h.clearBudget) budget := authenticated.Group("/budget") budget.POST("/new", h.newBudget) + budget.GET("/:budgetid", h.budgeting) + budget.GET("/:budgetid/:year/:month", h.budgetingForMonth) + budget.GET("/:budgetid/autocomplete/payees", h.autocompletePayee) + budget.GET("/:budgetid/autocomplete/categories", h.autocompleteCategories) + budget.DELETE("/:budgetid", h.deleteBudget) + budget.POST("/:budgetid/import/ynab", h.importYNAB) + budget.POST("/:budgetid/export/ynab/transactions", h.exportYNABTransactions) + budget.POST("/:budgetid/export/ynab/assignments", h.exportYNABAssignments) + budget.POST("/:budgetid/settings/clear", h.clearBudget) + budget.POST("/:budgetid/settings/clean-negative", h.cleanNegativeBudget) transaction := authenticated.Group("/transaction") transaction.POST("/new", h.newTransaction)