Files
dynamix-golang-sdk/pkg/cloudbroker/account/restore.go
T

65 lines
1.5 KiB
Go
Raw Normal View History

2025-09-23 14:34:24 +03:00
package account
import (
"context"
"net/http"
2026-08-21 18:12:55 +04:00
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v16/internal/validators"
2025-09-23 14:34:24 +03:00
)
// RestoreRequest struct to restore a deleted account
type RestoreRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
2026-10-30 16:04:15 +03:00
type wrapperRestoreRequest struct {
RestoreRequest
AsyncMode bool `url:"async_mode" json:"async_mode"`
}
2025-09-23 14:34:24 +03:00
// Restore restores a deleted account
2025-09-27 01:06:15 +03:00
func (a Account) Restore(ctx context.Context, req RestoreRequest) (string, error) {
2025-09-23 14:34:24 +03:00
err := validators.ValidateRequest(req)
if err != nil {
2025-09-27 01:06:15 +03:00
return "", validators.ValidationErrors(validators.GetErrors(err))
2025-09-23 14:34:24 +03:00
}
url := "/cloudbroker/account/restore"
2026-10-30 16:04:15 +03:00
reqWrapped := wrapperRestoreRequest{
RestoreRequest: req,
AsyncMode: false,
}
result, err := a.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
2025-09-23 14:34:24 +03:00
if err != nil {
2025-09-27 01:06:15 +03:00
return "", err
2025-09-23 14:34:24 +03:00
}
2025-09-27 01:06:15 +03:00
return string(result), nil
2025-09-23 14:34:24 +03:00
}
2026-10-30 16:04:15 +03:00
// 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 := "/cloudbroker/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
}