mirror of
https://github.com/yyhuni/xingrin.git
synced 2026-02-08 07:33:12 +08:00
- 修改所有import路径,从github.com/orbit/server改为github.com/yyhuni/orbit/server - 更新go.mod模块名为github.com/yyhuni/orbit/server - 调整内部引用路径,确保包导入一致性 - 修改.gitignore,新增AGENTS.md和WARP.md忽略规则 - 更新Scan请求中engineNames字段的绑定规则,改为必须且仅能包含一个元素
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package handler
|
|
|
|
import (
|
|
"errors"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/yyhuni/orbit/server/internal/dto"
|
|
"github.com/yyhuni/orbit/server/internal/service"
|
|
)
|
|
|
|
// AgentHandler handles agent API endpoints
|
|
type AgentHandler struct {
|
|
svc *service.AgentService
|
|
}
|
|
|
|
// NewAgentHandler creates a new agent handler
|
|
func NewAgentHandler(svc *service.AgentService) *AgentHandler {
|
|
return &AgentHandler{svc: svc}
|
|
}
|
|
|
|
// UpdateStatus updates scan status (called by Agent based on Worker exit code)
|
|
// PATCH /api/agent/scans/:id/status
|
|
func (h *AgentHandler) UpdateStatus(c *gin.Context) {
|
|
scanID, err := strconv.Atoi(c.Param("id"))
|
|
if err != nil {
|
|
dto.BadRequest(c, "Invalid scan ID")
|
|
return
|
|
}
|
|
|
|
var req dto.AgentUpdateStatusRequest
|
|
if !dto.BindJSON(c, &req) {
|
|
return
|
|
}
|
|
|
|
if err := h.svc.UpdateStatus(scanID, req.Status, req.ErrorMessage); err != nil {
|
|
if errors.Is(err, service.ErrAgentScanNotFound) {
|
|
dto.NotFound(c, "Scan not found")
|
|
return
|
|
}
|
|
if errors.Is(err, service.ErrAgentInvalidTransition) {
|
|
dto.BadRequest(c, "Invalid status transition")
|
|
return
|
|
}
|
|
dto.InternalError(c, "Failed to update status")
|
|
return
|
|
}
|
|
|
|
dto.Success(c, dto.AgentUpdateStatusResponse{Success: true})
|
|
}
|