Files
decort-golang-sdk/pkg/cloudbroker/user/list.go

73 lines
1.8 KiB
Go
Raw Normal View History

2023-06-23 15:13:22 +03:00
package user
import (
"context"
"encoding/json"
"net/http"
2024-04-16 14:26:06 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2023-06-23 15:13:22 +03:00
)
2023-10-23 12:40:54 +03:00
// ListRequest struct to get all non deleted user instances.
2023-06-23 15:13:22 +03:00
type ListRequest struct {
// Find by ID.
// Required: false
2024-04-16 14:26:06 +03:00
ByID string `url:"by_id,omitempty" json:"by_id,omitempty"`
2023-06-23 15:13:22 +03:00
// Find by active. True or False.
// Required: false
2024-05-31 13:35:39 +03:00
Active interface{} `url:"active,omitempty" json:"active,omitempty" validate:"omitempty,isBool"`
2023-06-23 15:13:22 +03:00
2025-07-15 17:39:18 +03:00
// Find by email.
// Required: false
Email string `url:"email,omitempty" json:"email,omitempty"`
2023-06-23 15:13:22 +03:00
// Find by serviceaccount. True or False.
// Required: false
2024-05-31 13:35:39 +03:00
ServiceAccount interface{} `url:"serviceaccount,omitempty" json:"serviceaccount,omitempty" validate:"omitempty,isBool"`
2023-06-23 15:13:22 +03:00
2024-04-16 14:26:06 +03:00
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
2023-06-23 15:13:22 +03:00
// Page number.
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size, maximum - 100.
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
2023-10-23 12:40:54 +03:00
// List gets all non deleted user instances as a ListUsers struct
2023-06-23 15:13:22 +03:00
func (u User) List(ctx context.Context, req ListRequest) (*ListUsers, error) {
2024-04-16 14:26:06 +03:00
2023-10-23 12:40:54 +03:00
res, err := u.ListRaw(ctx, req)
2023-06-23 15:13:22 +03:00
if err != nil {
return nil, err
}
list := ListUsers{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
2023-10-23 12:40:54 +03:00
// ListRaw gets all non deleted user instances as an array of bytes
func (u User) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
2024-04-16 14:26:06 +03:00
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
2023-10-23 12:40:54 +03:00
url := "/cloudbroker/user/list"
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}