From 4a7f4abedbfee3d2cbfc98cc778a1e7561ab7659 Mon Sep 17 00:00:00 2001 From: Mohammed Diaa Date: Tue, 12 Dec 2023 13:27:16 +0200 Subject: [PATCH] Refactor workflow version data struct type --- cmd/execute/execute.go | 14 ++-------- types/download.go | 60 ++++++++++++++++++++---------------------- 2 files changed, 30 insertions(+), 44 deletions(-) diff --git a/cmd/execute/execute.go b/cmd/execute/execute.go index 8a52e5a..3ab75b8 100644 --- a/cmd/execute/execute.go +++ b/cmd/execute/execute.go @@ -833,12 +833,7 @@ func readWorkflowYAMLandCreateVersion(fileName string, workflowName string, obje version := &types.WorkflowVersionDetailed{ WorkflowInfo: workflowID, Name: nil, - Data: struct { - Nodes map[string]*types.Node `json:"nodes"` - Connections []types.Connection `json:"connections"` - PrimitiveNodes map[string]*types.PrimitiveNode `json:"primitiveNodes"` - Annotations map[string]*types.Annotation `json:"annotations"` - }{ + Data: types.WorkflowVersionData{ Nodes: nodes, Connections: connections, PrimitiveNodes: primitiveNodes, @@ -962,12 +957,7 @@ func createToolWorkflow(wfName string, space *types.SpaceDetailed, project *type newVersion := &types.WorkflowVersionDetailed{ WorkflowInfo: workflowID, Name: nil, - Data: struct { - Nodes map[string]*types.Node `json:"nodes"` - Connections []types.Connection `json:"connections"` - PrimitiveNodes map[string]*types.PrimitiveNode `json:"primitiveNodes"` - Annotations map[string]*types.Annotation `json:"annotations"` - }{ + Data: types.WorkflowVersionData{ Nodes: map[string]*types.Node{ node.Name: node, }, diff --git a/types/download.go b/types/download.go index 5bb722e..2bfabea 100644 --- a/types/download.go +++ b/types/download.go @@ -35,23 +35,34 @@ type SubJobOutput struct { SignedURL string `json:"signed_url,omitempty"` } +type WorkflowVersionData struct { + Nodes map[string]*Node `json:"nodes"` + Connections []Connection `json:"connections"` + PrimitiveNodes map[string]*PrimitiveNode `json:"primitiveNodes"` + Annotations map[string]*Annotation `json:"annotation,omitempty"` +} + type WorkflowVersionDetailed struct { - ID uuid.UUID `json:"id"` - Version int `json:"version"` - WorkflowInfo uuid.UUID `json:"workflow_info"` - Name *string `json:"name,omitempty"` - Description string `json:"description"` - Public bool `json:"public"` - CreatedDate time.Time `json:"created_date"` - RunCount int `json:"run_count"` - MaxMachines Machines `json:"max_machines"` - Snapshot bool `json:"snapshot"` - Data struct { - Nodes map[string]*Node `json:"nodes"` - Connections []Connection `json:"connections"` - PrimitiveNodes map[string]*PrimitiveNode `json:"primitiveNodes"` - Annotations map[string]*Annotation `json:"annotations"` - } `json:"data"` + ID uuid.UUID `json:"id"` + Version int `json:"version"` + WorkflowInfo uuid.UUID `json:"workflow_info"` + Name *string `json:"name,omitempty"` + Description string `json:"description"` + Public bool `json:"public"` + CreatedDate time.Time `json:"created_date"` + RunCount int `json:"run_count"` + MaxMachines Machines `json:"max_machines"` + Snapshot bool `json:"snapshot"` + Data WorkflowVersionData `json:"data"` +} +type WorkflowVersionStripped struct { + ID uuid.UUID `json:"id"` + WorkflowInfo uuid.UUID `json:"workflow_info"` + Name *string `json:"name,omitempty"` + Description string `json:"description"` + MaxMachines Machines `json:"max_machines"` + Snapshot bool `json:"snapshot"` + Data WorkflowVersionData `json:"data"` } type Annotation struct { @@ -65,21 +76,6 @@ type Annotation struct { } `json:"coordinates"` } -type WorkflowVersionStripped struct { - ID uuid.UUID `json:"id"` - WorkflowInfo uuid.UUID `json:"workflow_info"` - Name *string `json:"name,omitempty"` - Description string `json:"description"` - MaxMachines Machines `json:"max_machines"` - Snapshot bool `json:"snapshot"` - Data struct { - Nodes map[string]*Node `json:"nodes"` - Connections []Connection `json:"connections"` - PrimitiveNodes map[string]*PrimitiveNode `json:"primitiveNodes"` - Annotations map[string]*Annotation `json:"annotations"` - } `json:"data"` -} - type Connection struct { Source struct { ID string `json:"id"` @@ -152,5 +148,5 @@ type NodeInput struct { Description *string `json:"description,omitempty"` WorkerConnected *bool `json:"workerConnected,omitempty"` Multi *bool `json:"multi,omitempty"` - Visible *bool `json:"visible"` + Visible *bool `json:"visible,omitempty"` }