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("/login", h.login)
router.GET("/register", h.register)
router.Group("").Use(h.verifyLoginWithRedirect).GET("/dashboard", h.dashboard)
withBudget := router.Group("")
{
withBudget.Use(h.verifyLoginWithRedirect)
withBudget.Use(h.getImportantData)
withBudget.GET("/dashboard", h.dashboard)
withBudget.GET("/budget/:budgetid", h.budget)
withBudget.GET("/budget/:budgetid/accounts", h.accounts)
withBudget.GET("/budget/:budgetid/account/:accountid", h.account)
withBudget.GET("/admin", h.admin)
withBudget.GET("/admin/clear-database", h.clearDatabase)
}
api := router.Group("/api/v1")
{
user := api.Group("/user")
{
unauthenticated := user.Group("")
{
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)
}
authenticated := user.Group("")
{
authenticated := api.Group("")
authenticated.Use(h.verifyLoginWithRedirect)
authenticated.GET("/logout", logout)
}
}
user := authenticated.Group("/user")
user.GET("/logout", logout)
budget := api.Group("/budget")
{
budget.Use(h.verifyLoginWithRedirect)
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")
}