v1.0.0
This commit is contained in:
@@ -7,11 +7,14 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get infromation about task
|
||||
type GetRequest struct {
|
||||
// ID of audit
|
||||
// Required: true
|
||||
AuditID string `url:"auditId"`
|
||||
}
|
||||
|
||||
func (trq GetRequest) Validate() error {
|
||||
func (trq GetRequest) validate() error {
|
||||
if trq.AuditID == "" {
|
||||
return errors.New("validation-error: field AuditID can not be empty")
|
||||
}
|
||||
@@ -19,27 +22,27 @@ func (trq GetRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t Tasks) Get(ctx context.Context, req GetRequest) (*AsyncTask, error) {
|
||||
err := req.Validate()
|
||||
// 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 := "/tasks/get"
|
||||
prefix := "/cloudapi"
|
||||
url := "/cloudapi/tasks/get"
|
||||
|
||||
url = prefix + url
|
||||
taskRaw, err := t.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
res, err := t.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
task := &AsyncTask{}
|
||||
err = json.Unmarshal(taskRaw, task)
|
||||
info := RecordAsyncTask{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return task, nil
|
||||
return &info, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -6,27 +6,33 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list of tasks
|
||||
type ListRequest struct {
|
||||
Page uint64 `url:"page"`
|
||||
Size uint64 `url:"size"`
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (t Tasks) List(ctx context.Context, req ListRequest) (TasksList, error) {
|
||||
url := "/tasks/list"
|
||||
prefix := "/cloudapi"
|
||||
// List gets list user API tasks with status PROCESSING
|
||||
func (t Tasks) List(ctx context.Context, req ListRequest) (ListTasks, error) {
|
||||
url := "/cloudapi/tasks/list"
|
||||
|
||||
url = prefix + url
|
||||
taskListRaw, err := t.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
res, err := t.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
taskList := TasksList{}
|
||||
err = json.Unmarshal(taskListRaw, &taskList)
|
||||
list := ListTasks{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return taskList, nil
|
||||
return list, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Global variable for converting field to desired data type
|
||||
type TaskResult int
|
||||
|
||||
// Method for convert field
|
||||
func (r *TaskResult) UnmarshalJSON(b []byte) error {
|
||||
if b[0] == '"' {
|
||||
b := b[1 : len(b)-1]
|
||||
@@ -35,17 +37,35 @@ func (r *TaskResult) UnmarshalJSON(b []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//AsyncTask represents a long task completion status
|
||||
type AsyncTask struct {
|
||||
AuditID string `json:"auditId"`
|
||||
Completed bool `json:"completed"`
|
||||
Error string `json:"error"`
|
||||
Log []string `json:"log"`
|
||||
Result TaskResult `json:"result"`
|
||||
Stage string `json:"stage"`
|
||||
Status string `json:"status"`
|
||||
UpdateTime uint64 `json:"updateTime"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
// Detailed information about task
|
||||
type RecordAsyncTask struct {
|
||||
// Audit ID
|
||||
AuditID string `json:"auditId"`
|
||||
|
||||
// Completed
|
||||
Completed bool `json:"completed"`
|
||||
|
||||
// Error
|
||||
Error string `json:"error"`
|
||||
|
||||
// List of logs
|
||||
Log []string `json:"log"`
|
||||
|
||||
// Final result
|
||||
Result TaskResult `json:"result"`
|
||||
|
||||
// Stage
|
||||
Stage string `json:"stage"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Update time
|
||||
UpdateTime uint64 `json:"updateTime"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type TasksList []AsyncTask
|
||||
// List of tasks
|
||||
type ListTasks []RecordAsyncTask
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
// User API tasks interface
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to tasks
|
||||
type Tasks struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for tasks endpoints
|
||||
func New(client interfaces.Caller) *Tasks {
|
||||
return &Tasks{
|
||||
client,
|
||||
|
||||
Reference in New Issue
Block a user