Changeset 0.35.0 (#209)
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit is contained in:
@@ -6,6 +6,7 @@ package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@@ -121,3 +122,62 @@ func (h *WorkflowAssignmentHandler) Complete(c *gin.Context) {
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"completed": true, "assignment_id": assignmentID})
|
||||
}
|
||||
|
||||
// CommentOnAssignment adds a review comment to an assignment.
|
||||
// POST /api/v1/workflow-assignments/:id/comment
|
||||
func (h *WorkflowAssignmentHandler) CommentOnAssignment(c *gin.Context) {
|
||||
assignmentID := c.Param("id")
|
||||
userID := c.GetString("user_id")
|
||||
|
||||
var body struct {
|
||||
Text string `json:"text"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&body); err != nil || body.Text == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "text is required"})
|
||||
return
|
||||
}
|
||||
|
||||
comment := store.ReviewComment{
|
||||
Text: body.Text,
|
||||
UserID: userID,
|
||||
CreatedAt: time.Now().UTC().Format(time.RFC3339),
|
||||
}
|
||||
|
||||
if err := h.stores.Workflows.AddReviewComment(c.Request.Context(), assignmentID, comment); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to add comment: " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true, "comment": comment})
|
||||
}
|
||||
|
||||
// GetAssignment returns a single assignment with review comments.
|
||||
// GET /api/v1/workflow-assignments/:id
|
||||
func (h *WorkflowAssignmentHandler) GetAssignment(c *gin.Context) {
|
||||
assignmentID := c.Param("id")
|
||||
|
||||
a, err := h.stores.Workflows.GetAssignmentByID(c.Request.Context(), assignmentID)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("assignment not found: %v", err)})
|
||||
return
|
||||
}
|
||||
|
||||
// Parse review_comments for the response
|
||||
var comments []store.ReviewComment
|
||||
if len(a.ReviewComments) > 0 {
|
||||
_ = json.Unmarshal(a.ReviewComments, &comments)
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"id": a.ID,
|
||||
"channel_id": a.ChannelID,
|
||||
"stage": a.Stage,
|
||||
"team_id": a.TeamID,
|
||||
"assigned_to": a.AssignedTo,
|
||||
"status": a.Status,
|
||||
"review_comments": comments,
|
||||
"created_at": a.CreatedAt,
|
||||
"claimed_at": a.ClaimedAt,
|
||||
"completed_at": a.CompletedAt,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user