package http import ( "net/http" "git.javil.eu/jacob1123/budgeteer/postgres" "github.com/gin-gonic/gin" "github.com/google/uuid" ) type AccountData struct { AlwaysNeededData Account *postgres.Account Categories []postgres.GetCategoriesRow Transactions []postgres.GetTransactionsForAccountRow Payees []postgres.Payee } func (h *Handler) account(c *gin.Context) { data := c.MustGet("data").(AlwaysNeededData) accountID := c.Param("accountid") accountUUID, err := uuid.Parse(accountID) if err != nil { c.Redirect(http.StatusTemporaryRedirect, "/login") return } account, err := h.Service.GetAccount(c.Request.Context(), accountUUID) if err != nil { c.AbortWithError(http.StatusNotFound, err) return } categories, err := h.Service.GetCategories(c.Request.Context(), data.Budget.ID) if err != nil { c.AbortWithError(http.StatusNotFound, err) return } transactions, err := h.Service.GetTransactionsForAccount(c.Request.Context(), accountUUID) if err != nil { c.AbortWithError(http.StatusNotFound, err) return } payees, err := h.Service.GetPayees(c.Request.Context(), data.Budget.ID) if err != nil { c.AbortWithError(http.StatusNotFound, err) return } d := AccountData{ data, &account, categories, transactions, payees, } c.HTML(http.StatusOK, "account.html", d) }