-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: workflow support #68
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -546,9 +546,50 @@ type ChangesApplyResponse struct { | |||||
Data []ChangesGetResponseData `json:"data,omitempty"` | ||||||
} | ||||||
|
||||||
|
||||||
type UpdateTenantRequest struct { | ||||||
Name string `json:"name"` | ||||||
Data map[string]interface{} `json:"data"` | ||||||
Identifier string `json:"identifier"` | ||||||
Name string `json:"name"` | ||||||
Data map[string]interface{} `json:"data"` | ||||||
Identifier string `json:"identifier"` | ||||||
} | ||||||
|
||||||
type WorkflowGetRequestOptions struct { | ||||||
Page int `json:"page,omitempty"` | ||||||
Limit int `json:"limit,omitempty"` | ||||||
} | ||||||
|
||||||
type WorkflowData struct { | ||||||
Id string `json:"_id,omitempty"` | ||||||
Name string `json:"name"` | ||||||
Description string `json:"description"` | ||||||
Active bool `json:"active,omitempty"` | ||||||
Draft bool `json:"draft,omitempty"` | ||||||
PreferenceSettings Channel `json:"preferenceSettings"` | ||||||
Critical bool `json:"critical"` | ||||||
Tags []string `json:"tags"` | ||||||
Steps []interface{} `json:"steps"` | ||||||
OrganizationId string `json:"_organizationId,omitempty"` | ||||||
CreatorId string `json:"_creatorId,omitempty"` | ||||||
EnvironmentId string `json:"_environmentId,omitempty"` | ||||||
Triggers []interface{} `json:"triggers,omitempty"` | ||||||
NotificationGroupID string `json:"_notificationGroupId,omitempty"` | ||||||
NotificationGroupId string `json:"notificationGroupId,omitempty"` | ||||||
ParentId string `json:"_parentId,omitempty"` | ||||||
Deleted bool `json:"deleted,omitempty"` | ||||||
DeletedAt string `json:"deletedAt,omitempty"` | ||||||
DeletedBy string `json:"deletedBy,omitempty"` | ||||||
NotificationGroup interface{} `json:"notificationGroup,omitempty"` | ||||||
Data interface{} `json:"data,omitempty"` | ||||||
WorkflowIntegrationStatus interface{} `json:"workflowIntegrationStatus,omitempty"` | ||||||
BlueprintId string `json:"blueprintId,omitempty"` | ||||||
} | ||||||
type WorkflowGetResponse struct { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Data WorkflowData `json:"data"` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
swagger seems to have wrong response structure list returns array of workflows, it was failing to unmarshal when i treied to test locally, can you test all workflow methods once, swagger doesnt seem 100% accurate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Cliftonz swagger needs to be updated here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you put in an issue on the main repo? |
||||||
} | ||||||
|
||||||
type WorkflowDeleteResponse struct { | ||||||
Data bool `json:"data"` | ||||||
} | ||||||
|
||||||
type WorkflowUpdateStatus struct { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Active bool `json:"active"` | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package lib | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
) | ||
|
||
type WorkflowService service | ||
|
||
func (w *WorkflowService) List(ctx context.Context, options *WorkflowGetRequestOptions) (*WorkflowGetResponse, error) { | ||
var resp WorkflowGetResponse | ||
URL := w.client.config.BackendURL.JoinPath("workflows") | ||
if options == nil { | ||
options = &WorkflowGetRequestOptions{} | ||
} | ||
queryParams, _ := json.Marshal(options) | ||
|
||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, URL.String(), bytes.NewBuffer(queryParams)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
_, err = w.client.sendRequest(req, &resp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &resp, nil | ||
} | ||
|
||
func (w *WorkflowService) Create(ctx context.Context, request WorkflowData) (*WorkflowData, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its ideal to create |
||
var resp WorkflowData | ||
URL := w.client.config.BackendURL.JoinPath("workflows") | ||
|
||
requestBody := WorkflowData{ | ||
Name: request.Name, | ||
NotificationGroupId: request.NotificationGroupId, | ||
Tags: request.Tags, | ||
Description: request.Description, | ||
Steps: request.Steps, | ||
Active: request.Active, | ||
Critical: request.Critical, | ||
PreferenceSettings: request.PreferenceSettings, | ||
BlueprintId: request.BlueprintId, | ||
Data: request.Data, | ||
} | ||
|
||
jsonBody, _ := json.Marshal(requestBody) | ||
b := bytes.NewBuffer(jsonBody) | ||
|
||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, URL.String(), b) | ||
if err != nil { | ||
return nil, err | ||
} | ||
_, err = w.client.sendRequest(req, &resp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &resp, nil | ||
} | ||
|
||
func (w *WorkflowService) Update(ctx context.Context, key string, request WorkflowData) (*WorkflowData, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as create |
||
|
||
var resp WorkflowData | ||
URL := w.client.config.BackendURL.JoinPath("workflows", key) | ||
|
||
requestBody := WorkflowData{ | ||
Name: request.Name, | ||
Tags: request.Tags, | ||
Description: request.Description, | ||
Steps: request.Steps, | ||
NotificationGroupId: request.NotificationGroupId, | ||
Critical: request.Critical, | ||
PreferenceSettings: request.PreferenceSettings, | ||
Data: request.Data, | ||
} | ||
|
||
jsonBody, _ := json.Marshal(requestBody) | ||
b := bytes.NewBuffer(jsonBody) | ||
|
||
req, err := http.NewRequestWithContext(ctx, http.MethodPut, URL.String(), b) | ||
if err != nil { | ||
return nil, err | ||
} | ||
_, err = w.client.sendRequest(req, &resp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &resp, nil | ||
} | ||
|
||
func (w *WorkflowService) Delete(ctx context.Context, key string) (*WorkflowDeleteResponse, error) { | ||
var resp WorkflowDeleteResponse | ||
URL := w.client.config.BackendURL.JoinPath("workflows", key) | ||
|
||
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, URL.String(), http.NoBody) | ||
if err != nil { | ||
return nil, err | ||
} | ||
_, err = w.client.sendRequest(req, &resp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &resp, nil | ||
} | ||
|
||
func (w *WorkflowService) Get(ctx context.Context, key string) (*WorkflowData, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. response type is not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same for update and updateStatus |
||
var resp WorkflowData | ||
URL := w.client.config.BackendURL.JoinPath("workflows", key) | ||
|
||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, URL.String(), bytes.NewBuffer([]byte{})) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
_, err = w.client.sendRequest(req, &resp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &resp, nil | ||
} | ||
|
||
func (w *WorkflowService) UpdateStatus(ctx context.Context, key string) (*WorkflowData, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its not accepting status? which is required in the api, so this is failing also |
||
var resp WorkflowData | ||
URL := w.client.config.BackendURL.JoinPath("workflows", key, "status") | ||
|
||
req, err := http.NewRequestWithContext(ctx, http.MethodPut, URL.String(), http.NoBody) | ||
if err != nil { | ||
return nil, err | ||
} | ||
_, err = w.client.sendRequest(req, &resp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &resp, nil | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason for keeping all these as interface, its ideal to have them as concrete structs gives better DX for the sdk users