Feat: edit node and get node info

This commit is contained in:
HFO4 2021-10-31 09:40:15 +08:00
parent 0d9aeb1d98
commit 34b02d5834
4 changed files with 29 additions and 1 deletions

2
assets

@ -1 +1 @@
Subproject commit 59890e6b22d69befa8b742a64967b6bab1bb4a3d
Subproject commit 8a61a8e4c238ed60a107ace23717cf8f03f957f6

View file

@ -476,3 +476,14 @@ func AdminDeleteNode(c *gin.Context) {
c.JSON(200, ErrorResponse(err))
}
}
// AdminGetNode 获取节点详情
func AdminGetNode(c *gin.Context) {
var service admin.NodeService
if err := c.ShouldBindUri(&service); err == nil {
res := service.Get()
c.JSON(200, res)
} else {
c.JSON(200, ErrorResponse(err))
}
}

View file

@ -458,6 +458,8 @@ func InitMasterRouter() *gin.Engine {
node.PATCH("enable/:id/:desired", controllers.AdminToggleNode)
// 删除节点
node.DELETE(":id", controllers.AdminDeleteNode)
// 获取节点
node.GET(":id", controllers.AdminGetNode)
}
}

View file

@ -83,6 +83,11 @@ func (service *ToggleNodeService) Toggle() serializer.Response {
return serializer.DBErr("找不到节点", err)
}
// 是否为系统节点
if node.ID <= 1 {
return serializer.Err(serializer.CodeNoPermissionErr, "系统节点无法更改", err)
}
if err = node.SetStatus(service.Desired); err != nil {
return serializer.DBErr("无法更改节点状态", err)
}
@ -121,3 +126,13 @@ func (service *NodeService) Delete() serializer.Response {
return serializer.Response{}
}
// Get 获取节点详情
func (service *NodeService) Get() serializer.Response {
node, err := model.GetNodeByID(service.ID)
if err != nil {
return serializer.Err(serializer.CodeNotFound, "节点不存在", err)
}
return serializer.Response{Data: node}
}