Beacon/routers/handlers/workflow.go

77 lines
1.8 KiB
Go

package handlers
import (
"beacon/services"
"github.com/gin-gonic/gin"
)
type WorkflowHandler struct {
service *services.WorkflowService
}
func NewWorkflowHandler() *WorkflowHandler {
return &WorkflowHandler{
service: &services.WorkflowService{},
}
}
// StartWorkflow POST /api/workflow/start
func (h *WorkflowHandler) StartWorkflow(c *gin.Context) {
err := h.service.Start("11")
if err != nil {
c.JSON(500, gin.H{
"code": -1,
"message": "Failed to start workflow",
})
return
}
c.JSON(200, gin.H{
"message": "Workflow started successfully",
})
}
// StopWorkflow POST /api/workflow/stop
func (h *WorkflowHandler) StopWorkflow(c *gin.Context) {
// 停止工作流的逻辑
// 这里可以调用 Temporal 的 API 来停止指定的工作流
// 例如,使用 WorkflowID 或 RunID 来停止工作流
c.JSON(200, gin.H{
"message": "Workflow stopped successfully",
})
}
// GetWorkflowStatus GET /api/workflow/status/{workflowID}
func (h *WorkflowHandler) GetWorkflowStatus(c *gin.Context) {
workflowID := c.Param("workflowID")
if workflowID == "" {
c.JSON(400, gin.H{"error": "Workflow ID is required"})
return
}
status, err := h.service.GetWorkflowStatus(workflowID)
if err != nil {
c.JSON(500, gin.H{"error": "Failed to get workflow status", "details": err.Error()})
return
}
c.JSON(200, gin.H{"status": status})
}
// GetWorkflowResults GET /api/workflow/results/{workflowID}
func (h *WorkflowHandler) GetWorkflowResults(c *gin.Context) {
workflowID := c.Param("workflowID")
if workflowID == "" {
c.JSON(400, gin.H{"error": "Workflow ID is required"})
return
}
results, err := h.service.GetWorkflowResults(workflowID)
if err != nil {
c.JSON(500, gin.H{"error": "Failed to get workflow results", "details": err.Error()})
return
}
c.JSON(200, gin.H{"results": results})
}