41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package server
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type ReconcileTransactionsRequest struct {
|
|
TransactionIDs []uuid.UUID
|
|
}
|
|
|
|
func (h *Handler) reconcileTransactions(c *gin.Context) {
|
|
var request ReconcileTransactionsRequest
|
|
err := c.BindJSON(&request)
|
|
if err != nil {
|
|
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("parse request: %w", err))
|
|
return
|
|
}
|
|
|
|
tx, err := h.Service.BeginTx(c.Request.Context(), &sql.TxOptions{})
|
|
if err != nil {
|
|
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("update transaction: %w", err))
|
|
return
|
|
}
|
|
db := h.Service.WithTx(tx)
|
|
for _, transactionID := range request.TransactionIDs {
|
|
err := db.SetTransactionReconciled(c.Request.Context(), transactionID)
|
|
if err != nil {
|
|
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("update transaction: %w", err))
|
|
return
|
|
}
|
|
}
|
|
tx.Commit()
|
|
|
|
c.JSON(http.StatusOK, SuccessResponse{fmt.Sprintf("Set status for %d transactions", len(request.TransactionIDs))})
|
|
}
|