Extract loading of accounts to middleware
This commit is contained in:
@ -8,26 +8,19 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type AccountsData struct {
|
||||
type AlwaysNeededData struct {
|
||||
Budget postgres.Budget
|
||||
Accounts []postgres.GetAccountsWithBalanceRow
|
||||
}
|
||||
|
||||
type AccountsData struct {
|
||||
AlwaysNeededData
|
||||
}
|
||||
|
||||
func (h *Handler) accounts(c *gin.Context) {
|
||||
budgetID := c.Param("budgetid")
|
||||
budgetUUID, err := uuid.Parse(budgetID)
|
||||
if err != nil {
|
||||
c.Redirect(http.StatusTemporaryRedirect, "/login")
|
||||
return
|
||||
}
|
||||
|
||||
accounts, err := h.Service.DB.GetAccountsWithBalance(c.Request.Context(), budgetUUID)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
base := c.MustGet("data").(AlwaysNeededData)
|
||||
d := AccountsData{
|
||||
Accounts: accounts,
|
||||
base,
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "accounts.html", d)
|
||||
|
Reference in New Issue
Block a user