mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/formancehq/payments/internal/connectors/metrics"
|
|
errorsutils "github.com/formancehq/payments/internal/utils/errors"
|
|
)
|
|
|
|
type User struct {
|
|
ID string `json:"Id"`
|
|
CreationDate int64 `json:"CreationDate"`
|
|
}
|
|
|
|
func (c *client) GetUsers(ctx context.Context, page int, pageSize int) ([]User, error) {
|
|
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "list_users")
|
|
|
|
endpoint := fmt.Sprintf("%s/v2.01/%s/users", c.endpoint, c.clientID)
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, http.NoBody)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create login request: %w", err)
|
|
}
|
|
|
|
q := req.URL.Query()
|
|
q.Add("per_page", strconv.Itoa(pageSize))
|
|
q.Add("page", fmt.Sprint(page))
|
|
q.Add("Sort", "CreationDate:ASC")
|
|
req.URL.RawQuery = q.Encode()
|
|
|
|
var users []User
|
|
statusCode, err := c.httpClient.Do(ctx, req, &users, nil)
|
|
if err != nil {
|
|
return nil, errorsutils.NewWrappedError(
|
|
fmt.Errorf("failed to get users: status code %d", statusCode),
|
|
err,
|
|
)
|
|
}
|
|
return users, nil
|
|
}
|