添加根据shell的id删除
This commit is contained in:
parent
ab2f5fd1b7
commit
cf404a97b9
16
dao/shell.go
16
dao/shell.go
|
|
@ -98,3 +98,19 @@ func FindShellWillRunByServer(server string, uid uint) []Shell {
|
||||||
}
|
}
|
||||||
return shells
|
return shells
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeleteShellByID(id, authId uint) bool {
|
||||||
|
var db2 *gorm.DB
|
||||||
|
if proto.Config.SERVER_SQL_LOG {
|
||||||
|
db2 = DB
|
||||||
|
} else {
|
||||||
|
db2 = DB.Debug()
|
||||||
|
}
|
||||||
|
result := db2.Where("id = ? and auth_id = ?", id, authId).Delete(&Shell{})
|
||||||
|
|
||||||
|
if result.Error != nil {
|
||||||
|
log.Printf("DeleteShellByID failed: %v", result.Error)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"net/http"
|
||||||
"videoplayer/proto"
|
"videoplayer/proto"
|
||||||
"videoplayer/service"
|
"videoplayer/service"
|
||||||
)
|
)
|
||||||
|
|
@ -32,12 +33,20 @@ type UpdateShellResp struct {
|
||||||
Status int `json:"status" form:"status"`
|
Status int `json:"status" form:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DeleteShellRequestID struct {
|
||||||
|
ID uint `json:"id" form:"id" binding:"required"`
|
||||||
|
}
|
||||||
|
type DeleteShellRequest struct {
|
||||||
|
Shells []DeleteShellRequestID `json:"shells" form:"shells" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
func SetUpShellGroup(router *gin.Engine) {
|
func SetUpShellGroup(router *gin.Engine) {
|
||||||
shellGroup := router.Group("/shell") //持续集成、部署
|
shellGroup := router.Group("/shell") //持续集成、部署
|
||||||
shellHandler := ShellHandler{}
|
shellHandler := ShellHandler{}
|
||||||
shellGroup.POST("/create", shellHandler.CreateShell)
|
shellGroup.POST("/create", shellHandler.CreateShell)
|
||||||
shellGroup.POST("/list", shellHandler.ListShell)
|
shellGroup.POST("/list", shellHandler.ListShell)
|
||||||
shellGroup.POST("/update", shellHandler.UpdateShell)
|
shellGroup.POST("/update", shellHandler.UpdateShell)
|
||||||
|
shellGroup.POST("/delete", shellHandler.DeleteShell)
|
||||||
shellGroup.POST("/server_will_run_list", shellHandler.ServerWillRun)
|
shellGroup.POST("/server_will_run_list", shellHandler.ServerWillRun)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,6 +93,41 @@ func (s *ShellHandler) UpdateShell(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DeleteShellResp struct {
|
||||||
|
Success []DeleteShellRequestID `json:"success" form:"success"`
|
||||||
|
Error []DeleteShellRequestID `json:"error" form:"error"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ShellHandler) DeleteShell(c *gin.Context) {
|
||||||
|
userId, _ := c.Get("id")
|
||||||
|
id := int(userId.(float64))
|
||||||
|
var req DeleteShellRequest
|
||||||
|
var resp proto.GeneralResp
|
||||||
|
|
||||||
|
if err := c.ShouldBind(&req); err != nil {
|
||||||
|
var delSuccessIDs []DeleteShellRequestID
|
||||||
|
var delErrorIDs []DeleteShellRequestID
|
||||||
|
for _, v := range req.Shells {
|
||||||
|
delSuccess := service.DeleteShellByID(v.ID, uint(id))
|
||||||
|
if delSuccess {
|
||||||
|
delSuccessIDs = append(delSuccessIDs, v)
|
||||||
|
} else {
|
||||||
|
delErrorIDs = append(delErrorIDs, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var delResp DeleteShellResp
|
||||||
|
delResp.Success = delSuccessIDs
|
||||||
|
delResp.Error = delErrorIDs
|
||||||
|
resp.Code = proto.SuccessCode
|
||||||
|
resp.Data = delResp
|
||||||
|
resp.Message = "success"
|
||||||
|
} else {
|
||||||
|
resp.Code = proto.ParameterError
|
||||||
|
resp.Message = "参数解析错误:" + err.Error()
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
|
}
|
||||||
|
|
||||||
type ServerWillRunReq struct {
|
type ServerWillRunReq struct {
|
||||||
Server string `json:"server"`
|
Server string `json:"server"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,10 @@ func FindShellByAuthID(id int) []dao.Shell {
|
||||||
return dao.FindShellByAuthID(id)
|
return dao.FindShellByAuthID(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeleteShellByID(id, authId uint) bool {
|
||||||
|
return dao.DeleteShellByID(id, authId)
|
||||||
|
}
|
||||||
|
|
||||||
func UpdateShellByID(id, authId uint, shellName, shellContent, server string, status int, shellResult string) bool {
|
func UpdateShellByID(id, authId uint, shellName, shellContent, server string, status int, shellResult string) bool {
|
||||||
return dao.UpdateShellByID(id, authId, shellName, shellContent, status, shellResult)
|
return dao.UpdateShellByID(id, authId, shellName, shellContent, status, shellResult)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue