droboticflow/internal/api/routes_workflows.go
d-robotics 994fa59982 ♻️ Split API route registration into per-domain routes_*.go files
routes.go keeps only the global middleware chain, the shared business-role
sets, and one mount call per domain: system, dashboard, acceptance, human
loop, annotation, projects, organization, workflows, runs, delivery, data
platform, and object sync. Role-only groups become withRoles/With on the
routes they guard, so each route's permission sits next to it instead of in
a role-shaped group far from the rest of its domain.

No route, handler, or access change: testdata/routes.golden (generated from
the pre-split router) is byte-identical, the Go known-failure gate passes,
and a live API smoke against a throwaway DB matched the access matrix for
every parameter-free GET route across six identities.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 18:50:40 +08:00

65 lines
4.4 KiB
Go

package api
import "github.com/go-chi/chi/v5"
// mountWorkflowRoutes registers workflows and their versions, releases,
// capture automation and runtime policy, templates, scan configs, operators,
// and AI-assisted generation.
func (server *server) mountWorkflowRoutes(router chi.Router) {
admin := server.withRoles(router, rolesAdmin...)
router.Get("/api/workflows/{id}", server.handleWorkflowsGet)
router.Get("/api/workflows/{id}/versions", server.handleWorkflowVersionsList)
admin.Get("/api/workflows/{id}/deletion-preview", server.handleWorkflowDeletionPreview)
router.Get("/api/workflow-releases/{id}", server.handleWorkflowReleaseGet)
router.With(server.requireAdminMonitoringAccess).Get("/api/workflows/{id}/runs", server.handleWorkflowRunsList)
router.Get("/api/workflows/{id}/capture-automation", server.handleCaptureAutomationGet)
router.Get("/api/workflows/{id}/runtime-policy", server.handleWorkflowRuntimePolicyGet)
router.Get("/api/workflows/{id}/runtime-policy/history", server.handleWorkflowRuntimePolicyHistory)
router.Get("/api/workflows/{id}/nodes/{nodeId}/source-state", server.handleWorkflowNodeSourceStateGet)
admin.Put("/api/workflows/{id}", server.handleWorkflowsUpdate)
admin.Post("/api/workflows/{id}/release", server.handleWorkflowRelease)
admin.Post("/api/workflows/{id}/versions", server.handleWorkflowCreateVersion)
admin.Post("/api/workflows/{id}/activate", server.handleWorkflowActivateVersion)
admin.Post("/api/workflows/{id}/archive", server.handleWorkflowArchive)
admin.Post("/api/workflows/{id}/restore", server.handleWorkflowRestore)
admin.Delete("/api/workflows/{id}", server.handleWorkflowsDelete)
admin.Delete("/api/workflows/{id}/nodes/{nodeId}/source-state", server.handleWorkflowNodeSourceStateDelete)
admin.Put("/api/workflows/{id}/capture-automation", server.handleCaptureAutomationUpdate)
admin.Patch("/api/workflows/{id}/runtime-policy", server.handleWorkflowRuntimePolicyPatch)
admin.Post("/api/workflows/{id}/capture-automation/records/{recordId}/cancel", server.handleCaptureRecordCancel)
admin.Post("/api/workflows/{id}/capture-automation/records/{recordId}/reprocess", server.handleCaptureRecordReprocess)
admin.Post("/api/workflows/{id}/capture-automation/records/{recordId}/discard", server.handleCaptureRecordDiscard)
admin.Post("/api/workflows/{id}/capture-automation/records/{recordId}/restore", server.handleCaptureRecordRestore)
router.Get("/api/templates", server.handleTemplatesList)
router.Get("/api/templates/{id}", server.handleTemplatesGet)
router.Get("/api/templates/{id}/releases", server.handleTemplateReleasesList)
admin.Post("/api/templates", server.handleTemplatesCreate)
admin.Post("/api/templates/{id}/publish", server.handleTemplatePublish)
admin.Put("/api/templates/{id}", server.handleTemplatesUpdate)
admin.Delete("/api/templates/{id}", server.handleTemplatesDelete)
router.Get("/api/scan-configs", server.handleScanConfigsList)
router.Get("/api/scan-configs/{id}", server.handleScanConfigsGet)
admin.Delete("/api/scan-configs/{id}", server.handleScanConfigsDelete)
router.Get("/api/operators", server.handleOperatorsList)
router.Get("/api/operators/{id}", server.handleOperatorsGet)
router.With(server.requirePocAcceptanceImportAccess).Post("/api/operators/image-archives/import", server.handleOperatorImageArchiveImport)
admin.Post("/api/operators", server.handleOperatorsCreate)
admin.Put("/api/operators/{id}", server.handleOperatorsUpdate)
admin.Delete("/api/operators/{id}", server.handleOperatorsDelete)
admin.Get("/api/operators/{id}/lightweight-files", server.handleOperatorLightweightFilesList)
admin.Patch("/api/operators/{id}/lightweight-files", server.handleOperatorLightweightFileMove)
admin.Delete("/api/operators/{id}/lightweight-files", server.handleOperatorLightweightFileDelete)
admin.Get("/api/operators/{id}/lightweight-files/content", server.handleOperatorLightweightFileContentGet)
admin.Put("/api/operators/{id}/lightweight-files/content", server.handleOperatorLightweightFileContentPut)
admin.Post("/api/operators/{id}/lightweight-files/directories", server.handleOperatorLightweightDirectoryCreate)
admin.Post("/api/operators/{id}/lightweight-files/upload", server.handleOperatorLightweightFileUpload)
router.Get("/api/ai/status", server.handleAIStatus)
admin.Post("/api/ai/operators/generate", server.handleAIOperatorGenerate)
admin.Post("/api/ai/workflows/generate", server.handleAIWorkflowGenerate)
}