Skip to content

Commit

Permalink
feat: workflow support
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth597 committed Oct 31, 2023
1 parent f8c99af commit db8ac64
Show file tree
Hide file tree
Showing 8 changed files with 746 additions and 5 deletions.
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"`
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 {
Data WorkflowData `json:"data"`
}

type WorkflowDeleteResponse struct {
Data bool `json:"data"`
}

type WorkflowUpdateStatus 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) {
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) {

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) {
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) {
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

0 comments on commit db8ac64

Please sign in to comment.