55 lines
1.1 KiB
Go
55 lines
1.1 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
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
d := TransactionData{
|
|
data,
|
|
&transaction,
|
|
&account,
|
|
categories,
|
|
}
|
|
|
|
c.HTML(http.StatusOK, "transaction.html", d)
|
|
}
|