- 新增 Go 语言后端服务(server/),包含用户认证、Agent管理、数据库连接等API - 新增 Python Agent 服务(agent/),实现Agent核心逻辑和工具集 - 前端从原生HTML迁移到Vue.js框架(web/src/) - 添加 Docker Compose 支持(docker-compose.yml) - 添加项目架构文档(docs/ARCHITECTURE.md) - 添加环境变量示例(.env.example)和本地启动脚本(start-local.ps1) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
81 lines
1.8 KiB
Go
81 lines
1.8 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"x-agents/server/internal/model"
|
|
"x-agents/server/internal/service"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type ApprovalHandler struct {
|
|
approvalService *service.ApprovalService
|
|
}
|
|
|
|
func NewApprovalHandler(approvalService *service.ApprovalService) *ApprovalHandler {
|
|
return &ApprovalHandler{approvalService: approvalService}
|
|
}
|
|
|
|
// Approve 处理审批请求
|
|
func (h *ApprovalHandler) Approve(c *gin.Context) {
|
|
var req struct {
|
|
RequestID string `json:"request_id" binding:"required"`
|
|
Approved bool `json:"approved"`
|
|
}
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
userID, exists := c.Get("user_id")
|
|
if !exists {
|
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
|
|
return
|
|
}
|
|
|
|
var result interface{}
|
|
var err error
|
|
|
|
if req.Approved {
|
|
result, err = h.approvalService.Approve(req.RequestID, userID.(string))
|
|
} else {
|
|
result, err = h.approvalService.Reject(req.RequestID, userID.(string))
|
|
}
|
|
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, result)
|
|
}
|
|
|
|
// GetStatus 获取审批状态
|
|
func (h *ApprovalHandler) GetStatus(c *gin.Context) {
|
|
requestID := c.Param("id")
|
|
|
|
result, err := h.approvalService.GetApproval(requestID)
|
|
if err != nil {
|
|
c.JSON(http.StatusNotFound, gin.H{"error": "request not found"})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, result)
|
|
}
|
|
|
|
// ListPending 获取待审批列表
|
|
func (h *ApprovalHandler) ListPending(c *gin.Context) {
|
|
result, err := h.approvalService.GetPendingApprovals()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
if result == nil {
|
|
result = []model.ToolApprovalRequest{}
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{"pending": result})
|
|
}
|