|
| 1 | +package v2 |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/1Panel-dev/1Panel/agent/app/api/v2/helper" |
| 5 | + "github.com/1Panel-dev/1Panel/agent/app/dto" |
| 6 | + "github.com/gin-gonic/gin" |
| 7 | +) |
| 8 | + |
| 9 | +// @Tags System Group |
| 10 | +// @Summary Create group |
| 11 | +// @Accept json |
| 12 | +// @Param request body dto.GroupCreate true "request" |
| 13 | +// @Success 200 |
| 14 | +// @Security ApiKeyAuth |
| 15 | +// @Security Timestamp |
| 16 | +// @Router /agent/groups [post] |
| 17 | +// @x-panel-log {"bodyKeys":["name","type"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"创建组 [name][type]","formatEN":"create group [name][type]"} |
| 18 | +func (b *BaseApi) CreateGroup(c *gin.Context) { |
| 19 | + var req dto.GroupCreate |
| 20 | + if err := helper.CheckBindAndValidate(&req, c); err != nil { |
| 21 | + return |
| 22 | + } |
| 23 | + |
| 24 | + if err := groupService.Create(req); err != nil { |
| 25 | + helper.InternalServer(c, err) |
| 26 | + return |
| 27 | + } |
| 28 | + helper.SuccessWithOutData(c) |
| 29 | +} |
| 30 | + |
| 31 | +// @Tags System Group |
| 32 | +// @Summary Delete group |
| 33 | +// @Accept json |
| 34 | +// @Param request body dto.OperateByID true "request" |
| 35 | +// @Success 200 |
| 36 | +// @Security ApiKeyAuth |
| 37 | +// @Security Timestamp |
| 38 | +// @Router /agent/groups/del [post] |
| 39 | +// @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]"} |
| 40 | +func (b *BaseApi) DeleteGroup(c *gin.Context) { |
| 41 | + var req dto.OperateByID |
| 42 | + if err := helper.CheckBindAndValidate(&req, c); err != nil { |
| 43 | + return |
| 44 | + } |
| 45 | + |
| 46 | + if err := groupService.Delete(req.ID); err != nil { |
| 47 | + helper.InternalServer(c, err) |
| 48 | + return |
| 49 | + } |
| 50 | + helper.SuccessWithOutData(c) |
| 51 | +} |
| 52 | + |
| 53 | +// @Tags System Group |
| 54 | +// @Summary Update group |
| 55 | +// @Accept json |
| 56 | +// @Param request body dto.GroupUpdate true "request" |
| 57 | +// @Success 200 |
| 58 | +// @Security ApiKeyAuth |
| 59 | +// @Security Timestamp |
| 60 | +// @Router /agent/groups/update [post] |
| 61 | +// @x-panel-log {"bodyKeys":["name","type"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"更新组 [name][type]","formatEN":"update group [name][type]"} |
| 62 | +func (b *BaseApi) UpdateGroup(c *gin.Context) { |
| 63 | + var req dto.GroupUpdate |
| 64 | + if err := helper.CheckBindAndValidate(&req, c); err != nil { |
| 65 | + return |
| 66 | + } |
| 67 | + |
| 68 | + if err := groupService.Update(req); err != nil { |
| 69 | + helper.InternalServer(c, err) |
| 70 | + return |
| 71 | + } |
| 72 | + helper.SuccessWithOutData(c) |
| 73 | +} |
| 74 | + |
| 75 | +// @Tags System Group |
| 76 | +// @Summary List groups |
| 77 | +// @Accept json |
| 78 | +// @Param request body dto.GroupSearch true "request" |
| 79 | +// @Success 200 {array} dto.OperateByType |
| 80 | +// @Security ApiKeyAuth |
| 81 | +// @Security Timestamp |
| 82 | +// @Router /agent/groups/search [post] |
| 83 | +func (b *BaseApi) ListGroup(c *gin.Context) { |
| 84 | + var req dto.OperateByType |
| 85 | + if err := helper.CheckBindAndValidate(&req, c); err != nil { |
| 86 | + return |
| 87 | + } |
| 88 | + |
| 89 | + list, err := groupService.List(req) |
| 90 | + if err != nil { |
| 91 | + helper.InternalServer(c, err) |
| 92 | + return |
| 93 | + } |
| 94 | + |
| 95 | + helper.SuccessWithData(c, list) |
| 96 | +} |
0 commit comments