Feat v0.3.4 team roles signoff (#18)
Some checks failed
CI/CD / detect-changes (push) Successful in 3s
CI/CD / test-frontend (push) Successful in 5s
CI/CD / test-go-pg (push) Failing after 2m45s
CI/CD / test-sqlite (push) Successful in 2m49s
CI/CD / build-and-deploy (push) Has been skipped

Co-authored-by: Jeffrey Smith <jasafpro@gmail.com>
Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #18.
This commit is contained in:
2026-03-28 01:15:33 +00:00
committed by xcaliber
parent dba718b914
commit 0773c86c27
24 changed files with 1039 additions and 20 deletions

View File

@@ -0,0 +1,72 @@
package handlers
import (
"net/http"
"github.com/gin-gonic/gin"
"switchboard-core/models"
"switchboard-core/store"
"switchboard-core/workflow"
)
// ── Signoff Handlers (v0.3.4) ─────────────────
// WorkflowSignoffHandler manages signoff HTTP endpoints.
type WorkflowSignoffHandler struct {
engine *workflow.Engine
stores store.Stores
}
// NewWorkflowSignoffHandler creates a signoff handler.
func NewWorkflowSignoffHandler(engine *workflow.Engine, stores store.Stores) *WorkflowSignoffHandler {
return &WorkflowSignoffHandler{engine: engine, stores: stores}
}
// Submit records a signoff (approve/reject) for the current stage of an instance.
// POST /api/v1/instances/:iid/signoffs
func (h *WorkflowSignoffHandler) Submit(c *gin.Context) {
userID := c.GetString("user_id")
instanceID := c.Param("iid")
var body struct {
Decision string `json:"decision" binding:"required,oneof=approve reject"`
Comment string `json:"comment"`
}
if err := c.ShouldBindJSON(&body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
so, err := h.engine.SubmitSignoff(c.Request.Context(), instanceID, userID, body.Decision, body.Comment)
if err != nil {
c.JSON(http.StatusConflict, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusCreated, so)
}
// List returns signoffs for the current stage of an instance.
// GET /api/v1/instances/:iid/signoffs
func (h *WorkflowSignoffHandler) List(c *gin.Context) {
instanceID := c.Param("iid")
// Get the instance to determine current stage
inst, err := h.stores.Workflows.GetInstance(c.Request.Context(), instanceID)
if err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "instance not found"})
return
}
signoffs, err := h.stores.Workflows.ListSignoffs(c.Request.Context(), instanceID, inst.CurrentStage)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "query failed"})
return
}
if signoffs == nil {
signoffs = []models.WorkflowSignoff{}
}
c.JSON(http.StatusOK, gin.H{"data": signoffs})
}