2022-08-30 10:49:07 +00:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2022-10-17 08:32:31 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/global"
|
2022-08-30 10:49:07 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags System Group
|
|
|
|
// @Summary Create group
|
|
|
|
// @Description 创建系统组
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.GroupOperate true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
2023-02-13 09:13:55 +00:00
|
|
|
// @Router /hosts/group [post]
|
2023-01-04 14:31:51 +00:00
|
|
|
// @x-panel-log {"bodyKeys":["name","type"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"创建组 [name][type]","formatEN":"create group [name][type]"}
|
2022-08-30 10:49:07 +00:00
|
|
|
func (b *BaseApi) CreateGroup(c *gin.Context) {
|
2022-08-31 15:16:10 +00:00
|
|
|
var req dto.GroupOperate
|
2022-08-30 10:49:07 +00:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := groupService.Create(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags System Group
|
|
|
|
// @Summary Delete group
|
|
|
|
// @Description 删除系统组
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.OperateByID true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
2023-02-13 09:13:55 +00:00
|
|
|
// @Router /hosts/group/del [post]
|
2023-01-04 14:31:51 +00:00
|
|
|
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFuntions":[{"input_colume":"id","input_value":"id","isList":false,"db":"groups","output_colume":"name","output_value":"name"}],"formatZH":"删除组 [name]","formatEN":"delete group [name]"}
|
2022-08-30 10:49:07 +00:00
|
|
|
func (b *BaseApi) DeleteGroup(c *gin.Context) {
|
2022-12-13 10:54:28 +00:00
|
|
|
var req dto.OperateByID
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
2022-08-30 10:49:07 +00:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-13 10:54:28 +00:00
|
|
|
if err := groupService.Delete(req.ID); err != nil {
|
2022-08-30 10:49:07 +00:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags System Group
|
|
|
|
// @Summary Update group
|
|
|
|
// @Description 更新系统组
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.GroupOperate true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
2023-02-13 09:13:55 +00:00
|
|
|
// @Router /hosts/group/update [post]
|
2023-01-04 14:31:51 +00:00
|
|
|
// @x-panel-log {"bodyKeys":["name","type"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"更新组 [name][type]","formatEN":"update group [name][type]"}
|
2022-08-30 10:49:07 +00:00
|
|
|
func (b *BaseApi) UpdateGroup(c *gin.Context) {
|
2022-08-31 15:16:10 +00:00
|
|
|
var req dto.GroupOperate
|
2022-08-30 10:49:07 +00:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-13 10:54:28 +00:00
|
|
|
if err := groupService.Update(req.ID, req.Name); err != nil {
|
2022-08-30 10:49:07 +00:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags System Group
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Summary List groups
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Description 查询系统组
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.GroupSearch true "request"
|
|
|
|
// @Success 200 {anrry} dto.GroupInfo
|
|
|
|
// @Security ApiKeyAuth
|
2023-02-13 09:13:55 +00:00
|
|
|
// @Router /hosts/group/search [post]
|
2022-08-30 10:49:07 +00:00
|
|
|
func (b *BaseApi) ListGroup(c *gin.Context) {
|
2022-08-31 15:16:10 +00:00
|
|
|
var req dto.GroupSearch
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
list, err := groupService.List(req)
|
2022-08-30 10:49:07 +00:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, list)
|
|
|
|
}
|