Add accounts

This commit is contained in:
2021-12-02 10:52:58 +00:00
parent e465b961a5
commit f760f9b855
6 changed files with 126 additions and 0 deletions

43
http/accounts.go Normal file
View File

@ -0,0 +1,43 @@
package http
import (
"net/http"
"git.javil.eu/jacob1123/budgeteer"
"git.javil.eu/jacob1123/budgeteer/postgres"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
type AccountData struct {
Token budgeteer.Token
Accounts []postgres.Account
}
func (h *Handler) accounts(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
}
accounts, err := h.Service.DB.GetAccounts(c.Request.Context(), budgetUUID)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
d := AccountData{
Token: token,
Accounts: accounts,
}
c.HTML(http.StatusOK, "accounts", d)
}