35 lines
650 B
Go
35 lines
650 B
Go
package http
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.javil.eu/jacob1123/budgeteer/postgres"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type AccountData struct {
|
|
Accounts []postgres.Account
|
|
}
|
|
|
|
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.GetAccounts(c.Request.Context(), budgetUUID)
|
|
if err != nil {
|
|
c.AbortWithError(http.StatusInternalServerError, err)
|
|
return
|
|
}
|
|
|
|
d := AccountData{
|
|
Accounts: accounts,
|
|
}
|
|
|
|
c.HTML(http.StatusOK, "accounts.html", d)
|
|
}
|