You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.1 KiB
51 lines
1.1 KiB
package account
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
)
|
|
|
|
// Request struct for delete group accounts
|
|
type DeleteAccountsRequest struct {
|
|
// IDs of accounts
|
|
// Required: true
|
|
AccountsIDs []uint64 `url:"accountIds" json:"accountIds"`
|
|
|
|
// Reason for deletion
|
|
// Required: true
|
|
Reason string `url:"reason" json:"reason"`
|
|
|
|
// Whether to completely destroy accounts or not
|
|
// Required: false
|
|
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
|
|
}
|
|
|
|
func (arq DeleteAccountsRequest) validate() error {
|
|
if len(arq.AccountsIDs) == 0 {
|
|
return errors.New("validation-error: field AccountIDs must be set")
|
|
}
|
|
if arq.Reason == "" {
|
|
return errors.New("validation-error: field Reason must be set")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// DeleteAccounts destroy a group of accounts
|
|
func (a Account) DeleteAccounts(ctx context.Context, req DeleteAccountsRequest) (bool, error) {
|
|
err := req.validate()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
url := "/cloudbroker/account/deleteAccounts"
|
|
|
|
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return true, nil
|
|
}
|