budgeteer/http/transaction-edit.go

63 lines
1.3 KiB
Go

package http
import (
"net/http"
"git.javil.eu/jacob1123/budgeteer/postgres"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
type TransactionData struct {
AlwaysNeededData
Transaction *postgres.Transaction
Account *postgres.Account
Categories []postgres.GetCategoriesRow
Payees []postgres.Payee
}
func (h *Handler) transaction(c *gin.Context) {
data := c.MustGet("data").(AlwaysNeededData)
transactionID := c.Param("transactionid")
transactionUUID, err := uuid.Parse(transactionID)
if err != nil {
c.Redirect(http.StatusTemporaryRedirect, "/login")
return
}
transaction, err := h.Service.GetTransaction(c.Request.Context(), transactionUUID)
if err != nil {
c.AbortWithError(http.StatusNotFound, err)
return
}
account, err := h.Service.GetAccount(c.Request.Context(), transaction.AccountID)
if err != nil {
c.AbortWithError(http.StatusNotFound, err)
return
}
categories, err := h.Service.GetCategories(c.Request.Context(), data.Budget.ID)
if err != nil {
c.AbortWithError(http.StatusNotFound, err)
return
}
payees, err := h.Service.GetPayees(c.Request.Context(), data.Budget.ID)
if err != nil {
c.AbortWithError(http.StatusNotFound, err)
return
}
d := TransactionData{
data,
&transaction,
&account,
categories,
payees,
}
c.HTML(http.StatusOK, "transaction.html", d)
}