feat: Implement node management features including creation, updating, and deletion

- Added CreateNode, UpdateNode, and DeleteNode functions in the controller for managing nodes.
- Introduced NodeInput struct for input validation during node creation and updates.
- Enhanced the Node model to include DiscoveryToken and Pending status.
- Updated the AgentRegister and AgentHeartbeat functions to utilize the new node management logic.
- Refactored the API router to include new routes for node management.
- Improved the frontend Node component to support node creation, editing, and deletion with appropriate UI feedback.
- Added tests to ensure the new functionality works as expected.
This commit is contained in:
ryan
2026-03-10 15:33:06 +08:00
parent 861d759f97
commit 05e75549d2
16 changed files with 916 additions and 296 deletions
+24 -3
View File
@@ -2,6 +2,7 @@ package controller
import (
"encoding/json"
"gin-template/model"
"gin-template/service"
"github.com/gin-gonic/gin"
"net/http"
@@ -16,7 +17,15 @@ func AgentRegister(c *gin.Context) {
})
return
}
node, err := service.RegisterNode(payload)
discoveryNode, ok := c.Get("discovery_node")
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{
"success": false,
"message": "无权进行此操作,Discovery Token 无效",
})
return
}
result, err := service.RegisterNode(discoveryNode.(*model.Node), payload)
if err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,
@@ -27,7 +36,7 @@ func AgentRegister(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "",
"data": node,
"data": result,
})
}
@@ -40,7 +49,15 @@ func AgentHeartbeat(c *gin.Context) {
})
return
}
node, err := service.HeartbeatNode(payload)
authNode, ok := c.Get("agent_node")
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{
"success": false,
"message": "无权进行此操作,Agent Token 无效",
})
return
}
node, err := service.HeartbeatNode(authNode.(*model.Node), payload)
if err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,
@@ -80,6 +97,10 @@ func AgentReportApplyLog(c *gin.Context) {
})
return
}
authNode, ok := c.Get("agent_node")
if ok {
payload.NodeID = authNode.(*model.Node).NodeID
}
log, err := service.ReportApplyLog(payload)
if err != nil {
c.JSON(http.StatusOK, gin.H{