Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 45 additions & 4 deletions lib/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Copy link
Contributor

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

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type WorkflowGetResponse struct {
type WorkflowListResponse struct {

Data WorkflowData `json:"data"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Data WorkflowData `json:"data"`
Data []WorkflowData `json:"data"`

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cliftonz swagger needs to be updated here.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type WorkflowUpdateStatus struct {
type WorkflowUpdateStatusPayload struct {

Active bool `json:"active"`
}
4 changes: 3 additions & 1 deletion lib/novu.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ type APIClient struct {
IntegrationsApi *IntegrationService
InboundParserApi *InboundParserService
LayoutApi *LayoutService
TenantApi *TenantService
TenantApi *TenantService
WorkflowApi *WorkflowService
}

type service struct {
Expand Down Expand Up @@ -112,6 +113,7 @@ func NewAPIClient(apiKey string, cfg *Config) *APIClient {
c.LayoutApi = (*LayoutService)(&c.common)
c.BlueprintApi = (*BlueprintService)(&c.common)
c.TenantApi = (*TenantService)(&c.common)
c.WorkflowApi = (*WorkflowService)(&c.common)
return c
}

Expand Down
138 changes: 138 additions & 0 deletions lib/workflow.go
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its ideal to create WorkFlowCreatePayload in model and use it here, otherwise the sdk method signature would confuse the users, asWorkflowData is a superset of the create payload

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response type is not WorkflowData itself its wrapped inside data

Copy link
Contributor

Choose a reason for hiding this comment

The 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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

}
Loading
Loading