2022-08-30 18:49:07 +08:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2022-10-17 16:32:31 +08: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"
|
2022-08-30 18:49:07 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags System Group
|
|
|
|
// @Summary Create group
|
|
|
|
// @Description 创建系统组
|
|
|
|
// @Accept json
|
2023-03-06 17:18:13 +08:00
|
|
|
// @Param request body dto.GroupCreate true "request"
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
2023-04-07 17:46:10 +08:00
|
|
|
// @Router /groups [post]
|
2023-10-07 15:46:44 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["name","type"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"创建组 [name][type]","formatEN":"create group [name][type]"}
|
2022-08-30 18:49:07 +08:00
|
|
|
func (b *BaseApi) CreateGroup(c *gin.Context) {
|
2023-03-06 17:18:13 +08:00
|
|
|
var req dto.GroupCreate
|
2023-10-27 14:19:26 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-08-30 18:49:07 +08:00
|
|
|
return
|
|
|
|
}
|
2023-10-27 14:19:26 +08:00
|
|
|
|
2022-08-30 18:49:07 +08:00
|
|
|
if err := groupService.Create(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags System Group
|
|
|
|
// @Summary Delete group
|
|
|
|
// @Description 删除系统组
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.OperateByID true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
2023-04-07 17:46:10 +08:00
|
|
|
// @Router /groups/del [post]
|
2023-10-07 15:46:44 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFunctions":[{"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 18:49:07 +08:00
|
|
|
func (b *BaseApi) DeleteGroup(c *gin.Context) {
|
2022-12-13 18:54:28 +08:00
|
|
|
var req dto.OperateByID
|
2023-10-27 14:19:26 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-08-30 18:49:07 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-13 18:54:28 +08:00
|
|
|
if err := groupService.Delete(req.ID); err != nil {
|
2022-08-30 18:49:07 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags System Group
|
|
|
|
// @Summary Update group
|
|
|
|
// @Description 更新系统组
|
|
|
|
// @Accept json
|
2023-03-06 17:18:13 +08:00
|
|
|
// @Param request body dto.GroupUpdate true "request"
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
2023-04-07 17:46:10 +08:00
|
|
|
// @Router /groups/update [post]
|
2023-10-07 15:46:44 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["name","type"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"更新组 [name][type]","formatEN":"update group [name][type]"}
|
2022-08-30 18:49:07 +08:00
|
|
|
func (b *BaseApi) UpdateGroup(c *gin.Context) {
|
2023-03-06 17:18:13 +08:00
|
|
|
var req dto.GroupUpdate
|
2023-10-27 14:19:26 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-08-30 18:49:07 +08:00
|
|
|
return
|
|
|
|
}
|
2023-10-27 14:19:26 +08:00
|
|
|
|
2023-03-06 17:18:13 +08:00
|
|
|
if err := groupService.Update(req); err != nil {
|
2022-08-30 18:49:07 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags System Group
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Summary List groups
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Description 查询系统组
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.GroupSearch true "request"
|
2023-05-30 15:30:57 +08:00
|
|
|
// @Success 200 {array} dto.GroupInfo
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Security ApiKeyAuth
|
2023-04-07 17:46:10 +08:00
|
|
|
// @Router /groups/search [post]
|
2022-08-30 18:49:07 +08:00
|
|
|
func (b *BaseApi) ListGroup(c *gin.Context) {
|
2022-08-31 23:16:10 +08:00
|
|
|
var req dto.GroupSearch
|
2023-10-27 14:19:26 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-08-31 23:16:10 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
list, err := groupService.List(req)
|
2022-08-30 18:49:07 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, list)
|
|
|
|
}
|