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

45 lines
1.1 KiB
Go

package v3
import (
"net/http"
"github.com/hanzo-fi/go-libs/v5/pkg/transport/api"
"github.com/hanzo-fi/payments/internal/api/backend"
"github.com/hanzo-fi/payments/pkg/domain/models"
"github.com/hanzo-fi/payments/internal/otel"
"github.com/google/uuid"
"go.opentelemetry.io/otel/attribute"
)
func poolsAddAccount(backend backend.Backend) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx, span := otel.Tracer().Start(r.Context(), "v3_poolsAddAccount")
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
}
span.SetAttributes(attribute.String("accountID", accountID(r)))
accountID, err := models.AccountIDFromString(accountID(r))
if err != nil {
otel.RecordError(span, err)
api.BadRequest(w, ErrInvalidID, err)
return
}
err = backend.PoolsAddAccount(ctx, id, accountID)
if err != nil {
otel.RecordError(span, err)
handleServiceErrors(w, r, err)
return
}
api.NoContent(w)
}
}