Add ReconcilationTransactionAmount

This commit is contained in:
2022-02-27 20:34:10 +00:00
parent 52503a4c92
commit 16bcf516f6
3 changed files with 26 additions and 5 deletions

View File

@@ -5,12 +5,14 @@ import (
"fmt"
"net/http"
"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
type ReconcileTransactionsRequest struct {
TransactionIDs []uuid.UUID
TransactionIDs []uuid.UUID `json:"transactionIds"`
ReconcilationTransactionAmount numeric.Numeric `json:"reconcilationTransactionAmount"`
}
func (h *Handler) reconcileTransactions(c *gin.Context) {
@@ -23,7 +25,7 @@ func (h *Handler) reconcileTransactions(c *gin.Context) {
tx, err := h.Service.BeginTx(c.Request.Context(), &sql.TxOptions{})
if err != nil {
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("update transaction: %w", err))
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("begin tx: %w", err))
return
}
db := h.Service.WithTx(tx)
@@ -34,7 +36,11 @@ func (h *Handler) reconcileTransactions(c *gin.Context) {
return
}
}
tx.Commit()
err = tx.Commit()
if err != nil {
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("commit: %w", err))
return
}
c.JSON(http.StatusOK, SuccessResponse{fmt.Sprintf("Set status for %d transactions", len(request.TransactionIDs))})
}