Files
dynamix-golang-sdk/pkg/cloudapi/account/restore.go
T
2026-10-30 16:04:15 +03:00

66 lines
1.5 KiB
Go

package account
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v16/internal/validators"
)
// RestoreRequest struct to restore a deleted account
type RestoreRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
type wrapperRestoreRequest struct {
RestoreRequest
AsyncMode bool `url:"async_mode" json:"async_mode"`
}
// Restore restores a deleted account
func (a Account) Restore(ctx context.Context, req RestoreRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/account/restore"
reqWrapped := wrapperRestoreRequest{
RestoreRequest: req,
AsyncMode: false,
}
result, err := a.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return "", err
}
return string(result), nil
}
// RestoreAsync restores a deleted account in async mode
func (a Account) RestoreAsync(ctx context.Context, req RestoreRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/account/restore"
reqWrapped := wrapperRestoreRequest{
RestoreRequest: req,
AsyncMode: true,
}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return "", err
}
return string(res), nil
}