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
|
2023-03-06 09:18:13 +00:00
|
|
|
// @Param request body dto.GroupCreate true "request"
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
2023-04-07 09:46:10 +00:00
|
|
|
// @Router /groups [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) {
|
2023-03-06 09:18:13 +00:00
|
|
|
var req dto.GroupCreate
|
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-04-07 09:46:10 +00:00
|
|
|
// @Router /groups/del [post]
|
2023-05-30 07:30:57 +00:00
|
|
|
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFuntions":[{"input_column":"id","input_value":"id","isList":false,"db":"groups","output_column":"name","output_value":"name"},{"input_column":"id","input_value":"id","isList":false,"db":"groups","output_column":"type","output_value":"type"}],"formatZH":"删除组 [type][name]","formatEN":"delete group [type][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
|
2023-03-06 09:18:13 +00:00
|
|
|
// @Param request body dto.GroupUpdate true "request"
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
2023-04-07 09:46:10 +00:00
|
|
|
// @Router /groups/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) {
|
2023-03-06 09:18:13 +00:00
|
|
|
var req dto.GroupUpdate
|
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
|
|
|
|
}
|
2023-03-06 09:18:13 +00:00
|
|
|
if err := groupService.Update(req); 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"
|
2023-05-30 07:30:57 +00:00
|
|
|
// @Success 200 {array} dto.GroupInfo
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Security ApiKeyAuth
|
2023-04-07 09:46:10 +00:00
|
|
|
// @Router /groups/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)
|
|
|
|
}
|