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.
53 lines
978 B
53 lines
978 B
package account
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
// Request struct for enable account
|
|
type EnableRequest struct {
|
|
// ID of account
|
|
// Required: true
|
|
AccountID uint64 `url:"accountId" json:"accountId"`
|
|
|
|
// Reason to enable
|
|
// Required: true
|
|
Reason string `url:"reason" json:"reason"`
|
|
}
|
|
|
|
func (arq EnableRequest) validate() error {
|
|
if arq.AccountID == 0 {
|
|
return errors.New("validation-error: field AccountID must be set")
|
|
}
|
|
if arq.Reason == "" {
|
|
return errors.New("field Reason must be set")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Enable enables an account
|
|
func (a Account) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
|
err := req.validate()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
url := "/cloudbroker/account/enable"
|
|
|
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
result, err := strconv.ParseBool(string(res))
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return result, nil
|
|
}
|