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.
49 lines
849 B
49 lines
849 B
package tasks
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
)
|
|
|
|
// Request struct for get infromation about task
|
|
type GetRequest struct {
|
|
// ID of audit
|
|
// Required: true
|
|
AuditID string `url:"auditId" json:"auditId"`
|
|
}
|
|
|
|
func (trq GetRequest) validate() error {
|
|
if trq.AuditID == "" {
|
|
return errors.New("validation-error: field AuditID can not be empty")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Get gets background API task status and result
|
|
func (t Tasks) Get(ctx context.Context, req GetRequest) (*RecordAsyncTask, error) {
|
|
err := req.validate()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
url := "/cloudapi/tasks/get"
|
|
|
|
res, err := t.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
info := RecordAsyncTask{}
|
|
|
|
err = json.Unmarshal(res, &info)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &info, nil
|
|
|
|
}
|