Files
payments/internal/api/v3/handler_pools_list.go

42 lines
1.1 KiB
Go

package v3
import (
"net/http"
"github.com/hanzo-fi/go-libs/v5/pkg/storage/bun/paginate"
"github.com/hanzo-fi/go-libs/v5/pkg/transport/api"
"github.com/hanzo-fi/go-libs/v5/pkg/types/pointer"
"github.com/hanzo-fi/payments/internal/api/backend"
"github.com/hanzo-fi/payments/internal/otel"
"github.com/hanzo-fi/payments/internal/storage"
)
func poolsList(backend backend.Backend) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx, span := otel.Tracer().Start(r.Context(), "v3_poolsList")
defer span.End()
query, err := paginate.Extract[storage.ListPoolsQuery](r, func() (*storage.ListPoolsQuery, error) {
options, err := getPagination(span, r, storage.PoolQuery{})
if err != nil {
return nil, err
}
return pointer.For(storage.NewListPoolsQuery(*options)), nil
})
if err != nil {
otel.RecordError(span, err)
api.BadRequest(w, ErrValidation, err)
return
}
cursor, err := backend.PoolsList(ctx, *query)
if err != nil {
otel.RecordError(span, err)
handleServiceErrors(w, r, err)
return
}
api.RenderCursor(w, *cursor)
}
}