Extract getImportantData to own file

This commit is contained in:
2021-12-04 22:58:52 +00:00
parent 6628a4849f
commit 61fa6ed776
4 changed files with 48 additions and 37 deletions

View File

@ -10,11 +10,12 @@ import (
)
type BudgetData struct {
Budget *postgres.Budget
AlwaysNeededData
Transactions []postgres.GetTransactionsForBudgetRow
}
func (h *Handler) budget(c *gin.Context) {
base := c.MustGet("data").(AlwaysNeededData)
budgetID := c.Param("budgetid")
budgetUUID, err := uuid.Parse(budgetID)
if err != nil {
@ -22,12 +23,6 @@ func (h *Handler) budget(c *gin.Context) {
return
}
budget, err := h.Service.DB.GetBudget(context.Background(), budgetUUID)
if err != nil {
c.AbortWithError(http.StatusNotFound, err)
return
}
transactions, err := h.Service.DB.GetTransactionsForBudget(context.Background(), budgetUUID)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
@ -35,8 +30,8 @@ func (h *Handler) budget(c *gin.Context) {
}
d := BudgetData{
Budget: &budget,
Transactions: transactions,
base,
transactions,
}
c.HTML(http.StatusOK, "budget.html", d)