-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflow_list.go
More file actions
109 lines (88 loc) · 2.54 KB
/
workflow_list.go
File metadata and controls
109 lines (88 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package unstructured
import (
"context"
"fmt"
"net/http"
"net/url"
"strconv"
"time"
)
// ListWorkflowsRequest represents the request to list workflows with optional filters.
type ListWorkflowsRequest struct {
DagNodeConfigurationID *string
SourceID *string
DestinationID *string
Status *WorkflowState
Page *int
PageSize *int
CreatedSince *time.Time
CreatedBefore *time.Time
Name *string
SortBy *string
SortDirection *SortDirection
ShowOnlySoftDeleted *bool
ShowRecommenderWorkflows *bool
}
// ListWorkflows retrieves a list of workflows with optional filtering and pagination.
func (c *Client) ListWorkflows(ctx context.Context, in *ListWorkflowsRequest) ([]Workflow, error) {
req, err := http.NewRequestWithContext(ctx,
http.MethodGet,
c.endpoint.JoinPath("workflows").String(),
nil,
)
if err != nil {
return nil, fmt.Errorf("failed to create HTTP request: %w", err)
}
if in != nil {
req.URL.RawQuery = buildWorkflowListQuery(in).Encode()
}
var workflows []Workflow
if err := c.do(req, &workflows); err != nil {
return nil, fmt.Errorf("failed to list workflows: %w", err)
}
return workflows, nil
}
// buildWorkflowListQuery builds the query parameters for the workflow list request.
func buildWorkflowListQuery(in *ListWorkflowsRequest) url.Values {
q := make(url.Values)
if in.DagNodeConfigurationID != nil {
q.Add("dag_node_configuration_id", *in.DagNodeConfigurationID)
}
if in.SourceID != nil {
q.Add("source_id", *in.SourceID)
}
if in.DestinationID != nil {
q.Add("destination_id", *in.DestinationID)
}
if in.Status != nil {
q.Add("status", string(*in.Status))
}
if in.Page != nil {
q.Add("page", strconv.Itoa(*in.Page))
}
if in.PageSize != nil {
q.Add("page_size", strconv.Itoa(*in.PageSize))
}
if in.CreatedSince != nil {
q.Add("created_since", in.CreatedSince.Format(time.RFC3339))
}
if in.CreatedBefore != nil {
q.Add("created_before", in.CreatedBefore.Format(time.RFC3339))
}
if in.Name != nil {
q.Add("name", *in.Name)
}
if in.SortBy != nil {
q.Add("sort_by", *in.SortBy)
}
if in.SortDirection != nil {
q.Add("sort_direction", string(*in.SortDirection))
}
if in.ShowOnlySoftDeleted != nil {
q.Add("show_only_soft_deleted", strconv.FormatBool(*in.ShowOnlySoftDeleted))
}
if in.ShowRecommenderWorkflows != nil {
q.Add("show_recommender_workflows", strconv.FormatBool(*in.ShowRecommenderWorkflows))
}
return q
}