Split budget and dashboard routes into own files

This commit is contained in:
2021-11-29 22:29:03 +00:00
parent f0a1d1d475
commit 6df72dc40d
6 changed files with 102 additions and 79 deletions

View File

@ -14,7 +14,6 @@ import (
"git.javil.eu/jacob1123/budgeteer/web"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
// Handler handles incoming requests
@ -65,35 +64,6 @@ func (h *Handler) Serve() {
router.Run(":1323")
}
func (h *Handler) budget(c *gin.Context) {
token, err := h.verifyLogin(c)
if err != nil {
c.Redirect(http.StatusTemporaryRedirect, "/login")
return
}
budgetID := c.Param("budgetid")
budgetUUID, err := uuid.Parse(budgetID)
if err != nil {
c.Redirect(http.StatusTemporaryRedirect, "/login")
return
}
budget, err := h.Service.DB.GetBudget(context.Background(), budgetUUID)
if err != nil {
c.AbortWithError(http.StatusUnauthorized, err)
return
}
d := TemplateData{
Token: token,
Budget: &budget,
budgetService: h.Service,
}
c.HTML(http.StatusOK, "budget", d)
}
func (h *Handler) newBudget(c *gin.Context) {
token, err := h.verifyLogin(c)
if err != nil {
@ -114,20 +84,6 @@ func (h *Handler) newBudget(c *gin.Context) {
}
}
func (h *Handler) dashboard(c *gin.Context) {
token, err := h.verifyLogin(c)
if err != nil {
c.Redirect(http.StatusTemporaryRedirect, "/login")
return
}
d := TemplateData{
Token: token,
budgetService: h.Service,
}
c.HTML(http.StatusOK, "dashboard", d)
}
func (h *Handler) verifyLogin(c *gin.Context) (budgeteer.Token, error) {
tokenString, err := c.Cookie(authCookie)
if err != nil {