UpdateInflightStatus updates the status of an inflight transaction based on the provided ID and status. It processes the transaction in batches according to the specified status (commit or void). If any errors occur during processing or if the status is unsupported, it responds with an appropriate e
(c *gin.Context)
| 389 | // - 400 Bad Request: If there's an error in updating the status or if the ID or status is missing or unsupported. |
| 390 | // - 200 OK: If the inflight transaction status is successfully updated. |
| 391 | func (a Api) UpdateInflightStatus(c *gin.Context) { |
| 392 | var resp *model.Transaction |
| 393 | id, passed := c.Params.Get("txID") |
| 394 | var req model2.InflightUpdate |
| 395 | if !passed { |
| 396 | c.JSON(http.StatusBadRequest, gin.H{"error": "id is required. pass id in the route /:id"}) |
| 397 | return |
| 398 | } |
| 399 | err := c.BindJSON(&req) |
| 400 | if err != nil { |
| 401 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 402 | return |
| 403 | } |
| 404 | |
| 405 | cnf, err := config.Fetch() |
| 406 | if err != nil { |
| 407 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 408 | return |
| 409 | } |
| 410 | ds, err := database.GetDBConnection(cnf) |
| 411 | if err != nil { |
| 412 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 413 | return |
| 414 | } |
| 415 | |
| 416 | amount := model.ApplyPrecisionWithDBLookup(&model.Transaction{Amount: req.Amount, TransactionID: id}, ds.Conn) |
| 417 | |
| 418 | if req.PreciseAmount != nil { |
| 419 | amount = req.PreciseAmount |
| 420 | } |
| 421 | |
| 422 | status := req.Status |
| 423 | if status == "commit" { |
| 424 | transaction, err := a.ledgerforge.ProcessTransactionInBatches(c.Request.Context(), id, amount, 1, false, a.ledgerforge.GetInflightTransactionsByParentID, a.ledgerforge.CommitWorker) |
| 425 | if err != nil { |
| 426 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 427 | return |
| 428 | } |
| 429 | if len(transaction) == 0 { |
| 430 | c.JSON(http.StatusBadRequest, gin.H{"error": "no transaction to commit"}) |
| 431 | return |
| 432 | } |
| 433 | resp = transformTransaction(transaction[0]) |
| 434 | } else if status == "void" { |
| 435 | transaction, err := a.ledgerforge.ProcessTransactionInBatches(c.Request.Context(), id, amount, 1, false, a.ledgerforge.GetInflightTransactionsByParentID, a.ledgerforge.VoidWorker) |
| 436 | if err != nil { |
| 437 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 438 | return |
| 439 | } |
| 440 | if len(transaction) == 0 { |
| 441 | c.JSON(http.StatusBadRequest, gin.H{"error": "no transaction to void"}) |
| 442 | return |
| 443 | } |
| 444 | resp = transformTransaction(transaction[0]) |
| 445 | } else { |
| 446 | c.JSON(http.StatusBadRequest, gin.H{"error": errors.New("status not supported. use either commit or void")}) |
| 447 | return |
| 448 | } |
nothing calls this directly
no test coverage detected