MCPcopy Create free account
hub / github.com/astercloud/aster / Create

Method Create

server/handlers/workflow.go:64–138  ·  view source on GitHub ↗

Create creates a new workflow

(c *gin.Context)

Source from the content-addressed store, hash-verified

62
63// Create creates a new workflow
64func (h *WorkflowHandler) Create(c *gin.Context) {
65 var req struct {
66 Name string `json:"name" binding:"required"`
67 Description string `json:"description"`
68 Version string `json:"version"`
69 Steps []WorkflowStep `json:"steps" binding:"required"`
70 Triggers []WorkflowTrigger `json:"triggers"`
71 Metadata map[string]any `json:"metadata"`
72 }
73
74 if err := c.ShouldBindJSON(&req); err != nil {
75 c.JSON(http.StatusBadRequest, gin.H{
76 "success": false,
77 "error": gin.H{
78 "code": "bad_request",
79 "message": err.Error(),
80 },
81 })
82 return
83 }
84
85 ctx := c.Request.Context()
86 now := time.Now()
87
88 version := req.Version
89 if version == "" {
90 version = "1.0.0"
91 }
92
93 // Convert steps to []any
94 steps := make([]any, len(req.Steps))
95 for i, step := range req.Steps {
96 steps[i] = step
97 }
98
99 // Convert triggers to []any
100 triggers := make([]any, len(req.Triggers))
101 for i, trigger := range req.Triggers {
102 triggers[i] = trigger
103 }
104
105 workflow := &WorkflowRecord{
106 ID: uuid.New().String(),
107 Name: req.Name,
108 Description: req.Description,
109 Version: version,
110 Steps: steps,
111 Triggers: triggers,
112 Status: "draft",
113 CreatedAt: now,
114 UpdatedAt: now,
115 Metadata: req.Metadata,
116 }
117
118 if err := (*h.store).Set(ctx, "workflows", workflow.ID, workflow); err != nil {
119 c.JSON(http.StatusInternalServerError, gin.H{
120 "success": false,
121 "error": gin.H{

Callers

nothing calls this directly

Calls 6

InfoFunction · 0.92
JSONMethod · 0.80
ErrorMethod · 0.65
ContextMethod · 0.65
SetMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected