79 lines
1.6 KiB
Go
79 lines
1.6 KiB
Go
package vins
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
)
|
|
|
|
// EnableRequest struct to enable VINS
|
|
type EnableRequest struct {
|
|
// VINS ID
|
|
// Required: true
|
|
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
|
}
|
|
|
|
type asyncWrapperEnableRequest struct {
|
|
EnableRequest
|
|
AsyncMode bool `url:"asyncMode"`
|
|
}
|
|
|
|
// Enable enables VINS
|
|
func (v VINS) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
|
err := validators.ValidateRequest(req)
|
|
if err != nil {
|
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
|
}
|
|
|
|
url := "/cloudapi/vins/enable"
|
|
|
|
syncReq := asyncWrapperEnableRequest{
|
|
EnableRequest: req,
|
|
AsyncMode: false,
|
|
}
|
|
|
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, syncReq)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
result, err := strconv.ParseBool(string(res))
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return result, nil
|
|
}
|
|
|
|
// Enable enables VINS by ID in async mode
|
|
func (v VINS) AsyncEnable(ctx context.Context, req EnableRequest) (string, error) {
|
|
err := validators.ValidateRequest(req)
|
|
if err != nil {
|
|
return "", validators.ValidationErrors(validators.GetErrors(err))
|
|
}
|
|
|
|
url := "/cloudapi/vins/enable"
|
|
|
|
asyncReq := asyncWrapperEnableRequest{
|
|
EnableRequest: req,
|
|
AsyncMode: true,
|
|
}
|
|
|
|
result, err := v.client.DecortApiCall(ctx, http.MethodPost, url, asyncReq)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
var resp string
|
|
|
|
err = json.Unmarshal(result, &resp)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return resp, nil
|
|
}
|