mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* feat(pools): add dynamic pools creation * fix(pools): fix missing json handling * feat(openapi): add pool type enum
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package v2
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/formancehq/go-libs/v3/api"
|
|
"github.com/formancehq/payments/internal/api/backend"
|
|
"github.com/formancehq/payments/internal/api/common"
|
|
"github.com/formancehq/payments/internal/otel"
|
|
"github.com/google/uuid"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
)
|
|
|
|
func poolsGet(backend backend.Backend) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
ctx, span := otel.Tracer().Start(r.Context(), "v2_poolsGet")
|
|
defer span.End()
|
|
|
|
span.SetAttributes(attribute.String("poolID", poolID(r)))
|
|
id, err := uuid.Parse(poolID(r))
|
|
if err != nil {
|
|
otel.RecordError(span, err)
|
|
api.BadRequest(w, ErrInvalidID, err)
|
|
return
|
|
}
|
|
|
|
pool, err := backend.PoolsGet(ctx, id)
|
|
if err != nil {
|
|
otel.RecordError(span, err)
|
|
handleServiceErrors(w, r, err)
|
|
return
|
|
}
|
|
|
|
data := &PoolResponse{
|
|
ID: pool.ID.String(),
|
|
Name: pool.Name,
|
|
Type: pool.Type,
|
|
Query: pool.Query,
|
|
}
|
|
|
|
accounts := make([]string, len(pool.PoolAccounts))
|
|
for i := range pool.PoolAccounts {
|
|
accounts[i] = pool.PoolAccounts[i].String()
|
|
}
|
|
data.Accounts = accounts
|
|
|
|
err = json.NewEncoder(w).Encode(api.BaseResponse[PoolResponse]{
|
|
Data: data,
|
|
})
|
|
if err != nil {
|
|
otel.RecordError(span, err)
|
|
common.InternalServerError(w, r, err)
|
|
return
|
|
}
|
|
}
|
|
}
|