QueueTransaction handles queuing a new transaction for later processing. It binds the incoming JSON request to a RecordTransaction object, validates it, and then queues the transaction. If any errors occur during validation or queuing, it responds with an appropriate error message. Parameters: - c:
(c *gin.Context)
| 148 | // - 400 Bad Request: If there's an error in binding JSON or validating the transaction. |
| 149 | // - 201 Created: If the transaction is successfully queued. |
| 150 | func (a Api) QueueTransaction(c *gin.Context) { |
| 151 | var newTransaction model2.RecordTransaction |
| 152 | // Bind the incoming JSON request to the newTransaction model |
| 153 | if err := c.ShouldBindJSON(&newTransaction); err != nil { |
| 154 | logrus.WithError(err).Error("failed to bind transaction JSON") |
| 155 | c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid input"}) |
| 156 | return |
| 157 | } |
| 158 | |
| 159 | // Validate the transaction data |
| 160 | err := newTransaction.ValidateRecordTransaction() |
| 161 | if err != nil { |
| 162 | handleRecordTransactionValidationError(c, err) |
| 163 | return |
| 164 | } |
| 165 | |
| 166 | // Queue the transaction using the LedgerForge service |
| 167 | resp, err := a.ledgerforge.QueueTransaction(c.Request.Context(), newTransaction.ToTransaction()) |
| 168 | if err != nil { |
| 169 | logrus.WithError(err).Error("failed to queue transaction") |
| 170 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 171 | return |
| 172 | } |
| 173 | |
| 174 | // Return a response with the queued transaction, properly transformed |
| 175 | c.JSON(http.StatusCreated, transformTransaction(resp)) |
| 176 | } |
| 177 | |
| 178 | // RefundTransaction processes a refund for a transaction based on the given ID. |
| 179 | // It retrieves the transaction to be refunded and processes it in batches. If any errors |
nothing calls this directly
no test coverage detected