Reorganize routes

This commit is contained in:
Jan Bader 2021-12-04 23:12:26 +00:00
parent 95f6e95fdd
commit 69bac9bc3f

View File

@ -46,45 +46,36 @@ func (h *Handler) Serve() {
router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "index.html", nil) }) router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "index.html", nil) })
router.GET("/login", h.login) router.GET("/login", h.login)
router.GET("/register", h.register) router.GET("/register", h.register)
router.Group("").Use(h.verifyLoginWithRedirect).GET("/dashboard", h.dashboard)
withBudget := router.Group("") withBudget := router.Group("")
{ withBudget.Use(h.verifyLoginWithRedirect)
withBudget.Use(h.verifyLoginWithRedirect) withBudget.Use(h.getImportantData)
withBudget.Use(h.getImportantData) withBudget.GET("/budget/:budgetid", h.budget)
withBudget.GET("/dashboard", h.dashboard) withBudget.GET("/budget/:budgetid/accounts", h.accounts)
withBudget.GET("/budget/:budgetid", h.budget) withBudget.GET("/budget/:budgetid/account/:accountid", h.account)
withBudget.GET("/budget/:budgetid/accounts", h.accounts) withBudget.GET("/admin", h.admin)
withBudget.GET("/budget/:budgetid/account/:accountid", h.account) withBudget.GET("/admin/clear-database", h.clearDatabase)
withBudget.GET("/admin", h.admin)
withBudget.GET("/admin/clear-database", h.clearDatabase)
}
api := router.Group("/api/v1") api := router.Group("/api/v1")
{
user := api.Group("/user") unauthenticated := api.Group("/user")
{ unauthenticated.GET("/login", func(c *gin.Context) { c.Redirect(http.StatusPermanentRedirect, "/login") })
unauthenticated := user.Group("") unauthenticated.POST("/login", h.loginPost)
{ unauthenticated.POST("/register", h.registerPost)
unauthenticated.GET("/login", func(c *gin.Context) { c.Redirect(http.StatusPermanentRedirect, "/login") })
unauthenticated.POST("/login", h.loginPost) authenticated := api.Group("")
unauthenticated.POST("/register", h.registerPost) authenticated.Use(h.verifyLoginWithRedirect)
}
authenticated := user.Group("") user := authenticated.Group("/user")
{ user.GET("/logout", logout)
authenticated.Use(h.verifyLoginWithRedirect)
authenticated.GET("/logout", logout) budget := api.Group("/budget")
} budget.POST("/new", h.newBudget)
}
budget := api.Group("/budget") transaction := api.Group("/transaction")
{ transaction.POST("/new", h.newTransaction)
budget.Use(h.verifyLoginWithRedirect) transaction.POST("/import/ynab", h.importYNAB)
budget.POST("/new", h.newBudget)
}
transaction := api.Group("/transaction")
{
transaction.Use(h.verifyLoginWithRedirect)
transaction.POST("/new", h.newTransaction)
transaction.POST("/import/ynab", h.importYNAB)
}
}
router.Run(":1323") router.Run(":1323")
} }