mirror of
https://github.com/usual2970/certimate.git
synced 2025-08-14 13:21:45 +00:00
.github
.vscode
docker
internal
app
applicant
certificate
deployer
domain
notify
pkg
repository
rest
handlers
certificate.go
notify.go
statistics.go
workflow.go
resp
routes
scheduler
statistics
workflow
migrations
ui
.dockerignore
.editorconfig
.gitignore
.goreleaser.yml
CHANGELOG.md
CONTRIBUTING.md
CONTRIBUTING_EN.md
Dockerfile
LICENSE.md
Makefile
README.md
README_EN.md
go.mod
go.sum
main.go
nixpacks.toml
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package handlers
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/pocketbase/pocketbase/core"
|
|
"github.com/pocketbase/pocketbase/tools/router"
|
|
|
|
"github.com/usual2970/certimate/internal/domain/dtos"
|
|
"github.com/usual2970/certimate/internal/rest/resp"
|
|
)
|
|
|
|
type workflowService interface {
|
|
StartRun(ctx context.Context, req *dtos.WorkflowStartRunReq) error
|
|
CancelRun(ctx context.Context, req *dtos.WorkflowCancelRunReq) error
|
|
Shutdown(ctx context.Context)
|
|
}
|
|
|
|
type WorkflowHandler struct {
|
|
service workflowService
|
|
}
|
|
|
|
func NewWorkflowHandler(router *router.RouterGroup[*core.RequestEvent], service workflowService) {
|
|
handler := &WorkflowHandler{
|
|
service: service,
|
|
}
|
|
|
|
group := router.Group("/workflows")
|
|
group.POST("/{workflowId}/runs", handler.run)
|
|
group.POST("/{workflowId}/runs/{runId}/cancel", handler.cancel)
|
|
}
|
|
|
|
func (handler *WorkflowHandler) run(e *core.RequestEvent) error {
|
|
req := &dtos.WorkflowStartRunReq{}
|
|
req.WorkflowId = e.Request.PathValue("workflowId")
|
|
if err := e.BindBody(req); err != nil {
|
|
return resp.Err(e, err)
|
|
}
|
|
|
|
if err := handler.service.StartRun(e.Request.Context(), req); err != nil {
|
|
return resp.Err(e, err)
|
|
}
|
|
|
|
return resp.Ok(e, nil)
|
|
}
|
|
|
|
func (handler *WorkflowHandler) cancel(e *core.RequestEvent) error {
|
|
req := &dtos.WorkflowCancelRunReq{}
|
|
req.WorkflowId = e.Request.PathValue("workflowId")
|
|
req.RunId = e.Request.PathValue("runId")
|
|
|
|
if err := handler.service.CancelRun(e.Request.Context(), req); err != nil {
|
|
return resp.Err(e, err)
|
|
}
|
|
|
|
return resp.Ok(e, nil)
|
|
}
|