61 lines
1.2 KiB
Go
61 lines
1.2 KiB
Go
package http
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.javil.eu/jacob1123/budgeteer/postgres"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type AlwaysNeededData struct {
|
|
Budget postgres.Budget
|
|
Accounts []postgres.GetAccountsWithBalanceRow
|
|
}
|
|
|
|
type AccountsData struct {
|
|
AlwaysNeededData
|
|
}
|
|
|
|
func (h *Handler) accounts(c *gin.Context) {
|
|
base := c.MustGet("data").(AlwaysNeededData)
|
|
d := AccountsData{
|
|
base,
|
|
}
|
|
|
|
c.HTML(http.StatusOK, "accounts.html", d)
|
|
}
|
|
|
|
type AccountData struct {
|
|
Account *postgres.Account
|
|
Transactions []postgres.GetTransactionsForAccountRow
|
|
}
|
|
|
|
func (h *Handler) account(c *gin.Context) {
|
|
accountID := c.Param("accountid")
|
|
accountUUID, err := uuid.Parse(accountID)
|
|
if err != nil {
|
|
c.Redirect(http.StatusTemporaryRedirect, "/login")
|
|
return
|
|
}
|
|
|
|
account, err := h.Service.DB.GetAccount(c.Request.Context(), accountUUID)
|
|
if err != nil {
|
|
c.AbortWithError(http.StatusNotFound, err)
|
|
return
|
|
}
|
|
|
|
transactions, err := h.Service.DB.GetTransactionsForAccount(c.Request.Context(), accountUUID)
|
|
if err != nil {
|
|
c.AbortWithError(http.StatusNotFound, err)
|
|
return
|
|
}
|
|
|
|
d := AccountData{
|
|
Account: &account,
|
|
Transactions: transactions,
|
|
}
|
|
|
|
c.HTML(http.StatusOK, "account.html", d)
|
|
}
|