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 account
|
|
type DeleteRequest struct {
|
|
// ID of account to delete
|
|
// Required: true
|
|
AccountID uint64 `url:"accountId"`
|
|
|
|
// Reason to delete
|
|
// Required: true
|
|
Reason string `url:"reason"`
|
|
|
|
// Whether to completely delete the account
|
|
// Required: false
|
|
Permanently bool `url:"permanently,omitempty"`
|
|
}
|
|
|
|
func (arq DeleteRequest) validate() error {
|
|
if arq.AccountID == 0 {
|
|
return errors.New("validation-error: field AccountID must be set")
|
|
}
|
|
if arq.Reason == "" {
|
|
return errors.New("validation-error: field Reason must be set")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Delete completes delete an account from the system Returns true if account is deleted or was already deleted or never existed
|
|
func (a Account) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
|
err := req.validate()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
url := "/cloudbroker/account/delete"
|
|
|
|
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return true, nil
|
|
}
|