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.
|
|
|
|
func HandleTrackTx(c echo.Context) error {
|
|
|
|
var (
|
|
|
|
cu = c.Get("cu").(*custodial.Custodial)
|
|
|
|
txStatusRequest struct {
|
2023-02-21 18:34:22 +01:00
|
|
|
TrackingId string `param:"trackingId" validate:"required,uuid"`
|
|
|
|
}
|
2023-02-24 17:46:46 +01:00
|
|
|
)
|
2023-02-21 18:34:22 +01:00
|
|
|
|
2023-02-24 17:46:46 +01:00
|
|
|
if err := c.Bind(&txStatusRequest); err != nil {
|
|
|
|
return NewBadRequestError(err)
|
|
|
|
}
|
2023-02-21 18:34:22 +01:00
|
|
|
|
2023-02-24 17:46:46 +01:00
|
|
|
if err := c.Validate(txStatusRequest); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-21 18:34:22 +01:00
|
|
|
|
2023-02-24 17:46:46 +01:00
|
|
|
txs, err := cu.PgStore.GetTxStatusByTrackingId(c.Request().Context(), txStatusRequest.TrackingId)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2023-02-21 18:34:22 +01:00
|
|
|
}
|
2023-02-24 17:46:46 +01:00
|
|
|
|
|
|
|
return c.JSON(http.StatusOK, OkResp{
|
|
|
|
Ok: true,
|
|
|
|
Result: H{
|
|
|
|
"transactions": txs,
|
|
|
|
},
|
|
|
|
})
|
2023-02-21 18:34:22 +01:00
|
|
|
}
|