Actually handle passed reconciliation amount
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"git.javil.eu/jacob1123/budgeteer/postgres"
|
||||
"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
||||
@@ -13,17 +14,24 @@ import (
|
||||
|
||||
type ReconcileTransactionsRequest struct {
|
||||
TransactionIDs []uuid.UUID `json:"transactionIds"`
|
||||
ReconcilationTransactionAmount numeric.Numeric `json:"reconcilationTransactionAmount"`
|
||||
ReconcilationTransactionAmount numeric.Numeric `json:"reconciliationTransactionAmount"`
|
||||
}
|
||||
|
||||
type ReconcileTransactionsResponse struct {
|
||||
Message string
|
||||
ReconcilationTransaction []postgres.GetTransactionsForAccountRow
|
||||
Message string
|
||||
ReconciliationTransaction *postgres.DisplayTransaction
|
||||
}
|
||||
|
||||
func (h *Handler) reconcileTransactions(c *gin.Context) {
|
||||
accountID := c.Param("accountid")
|
||||
accountUUID, err := uuid.Parse(accountID)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
var request ReconcileTransactionsRequest
|
||||
err := c.BindJSON(&request)
|
||||
err = c.BindJSON(&request)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("parse request: %w", err))
|
||||
return
|
||||
@@ -48,8 +56,32 @@ func (h *Handler) reconcileTransactions(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var reconciliationTransaction *postgres.DisplayTransaction
|
||||
if !request.ReconcilationTransactionAmount.IsZero() {
|
||||
createTransaction := postgres.CreateTransactionParams{
|
||||
Date: time.Now(),
|
||||
Memo: "Reconciliation Transaction",
|
||||
Amount: request.ReconcilationTransactionAmount,
|
||||
AccountID: accountUUID,
|
||||
Status: "Reconciled",
|
||||
}
|
||||
newTransaction, err := h.Service.CreateTransaction(c.Request.Context(), createTransaction)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("insert new transaction: %w", err))
|
||||
return
|
||||
}
|
||||
|
||||
transaction, err := h.Service.GetTransaction(c.Request.Context(), newTransaction.ID)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("get created transaction: %w", err))
|
||||
return
|
||||
}
|
||||
|
||||
reconciliationTransaction = &transaction
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, ReconcileTransactionsResponse{
|
||||
Message: fmt.Sprintf("Set status for %d transactions", len(request.TransactionIDs)),
|
||||
ReconcilationTransaction: nil,
|
||||
Message: fmt.Sprintf("Set status for %d transactions", len(request.TransactionIDs)),
|
||||
ReconciliationTransaction: reconciliationTransaction,
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user