2023-02-21 18:34:22 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2023-02-24 17:46:46 +01:00
|
|
|
"github.com/grassrootseconomics/cic-custodial/internal/custodial"
|
2023-02-21 18:34:22 +01:00
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
2023-02-24 17:46:46 +01:00
|
|
|
// HandleTxStatus route.
|
|
|
|
// GET: /api/track/:trackingId
|
|
|
|
// Route param:
|
|
|
|
// trackingId -> tracking UUID
|
|
|
|
// Returns array of tx status.
|
2023-03-28 08:39:44 +02:00
|
|
|
func HandleTrackTx(cu *custodial.Custodial) func(echo.Context) error {
|
|
|
|
return func(c echo.Context) error {
|
|
|
|
var (
|
|
|
|
txStatusRequest struct {
|
|
|
|
TrackingId string `param:"trackingId" validate:"required,uuid"`
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
if err := c.Bind(&txStatusRequest); err != nil {
|
|
|
|
return NewBadRequestError(err)
|
2023-02-21 18:34:22 +01:00
|
|
|
}
|
|
|
|
|
2023-03-28 08:39:44 +02:00
|
|
|
if err := c.Validate(txStatusRequest); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-21 18:34:22 +01:00
|
|
|
|
2023-04-11 12:14:49 +02:00
|
|
|
txs, err := cu.Store.GetTxStatus(c.Request().Context(), txStatusRequest.TrackingId)
|
2023-03-28 08:39:44 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-21 18:34:22 +01:00
|
|
|
|
2023-03-28 08:39:44 +02:00
|
|
|
return c.JSON(http.StatusOK, OkResp{
|
|
|
|
Ok: true,
|
|
|
|
Result: H{
|
2023-04-11 12:14:49 +02:00
|
|
|
"transaction": txs,
|
2023-03-28 08:39:44 +02:00
|
|
|
},
|
|
|
|
})
|
2023-02-21 18:34:22 +01:00
|
|
|
}
|
|
|
|
}
|