1Panel/backend/app/api/v1/website_group.go

90 lines
3.2 KiB
Go
Raw Normal View History

2022-10-28 17:04:57 +08:00
package v1
import (
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
2022-12-13 17:20:13 +08:00
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
2022-10-28 17:04:57 +08:00
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/gin-gonic/gin"
)
2023-01-04 22:31:51 +08:00
// @Tags Website Group
// @Summary List website groups
2023-01-04 22:31:51 +08:00
// @Description 获取网站组
// @Success 200 {anrry} model.WebsiteGroup
// @Security ApiKeyAuth
// @Router /websites/groups [get]
2022-11-02 15:19:14 +08:00
func (b *BaseApi) GetWebGroups(c *gin.Context) {
2022-10-28 17:04:57 +08:00
list, err := websiteGroupService.GetGroups()
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, list)
}
2022-11-02 15:19:14 +08:00
2023-01-04 22:31:51 +08:00
// @Tags Website Group
// @Summary Create website group
// @Description 创建网站组
// @Accept json
// @Param request body request.WebsiteGroupCreate true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /websites/groups [post]
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"创建网站组 [name]","formatEN":"Create website groups [name]"}
2022-11-02 15:19:14 +08:00
func (b *BaseApi) CreateWebGroup(c *gin.Context) {
2022-12-13 17:20:13 +08:00
var req request.WebsiteGroupCreate
2022-11-02 15:19:14 +08:00
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
if err := websiteGroupService.CreateGroup(req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}
2022-11-02 18:18:20 +08:00
2023-01-04 22:31:51 +08:00
// @Tags Website Group
// @Summary Update website group
// @Description 更新网站组
// @Accept json
// @Param request body request.WebsiteGroupUpdate true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /websites/groups/update [post]
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"更新网站组 [name]","formatEN":"Update website groups [name]"}
2022-11-02 18:18:20 +08:00
func (b *BaseApi) UpdateWebGroup(c *gin.Context) {
2022-12-13 17:20:13 +08:00
var req request.WebsiteGroupUpdate
2022-11-02 18:18:20 +08:00
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
if err := websiteGroupService.UpdateGroup(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 Website Group
// @Summary Delete website group
// @Description 删除网站组
// @Accept json
// @Param request body request.WebsiteResourceReq true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /websites/groups/del [post]
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFuntions":[{"input_colume":"id","input_value":"id","isList":false,"db":"website_groups","output_colume":"name","output_value":"name"}],"formatZH":"删除网站组 [name]","formatEN":"Delete website group [name]"}
2022-11-02 18:18:20 +08:00
func (b *BaseApi) DeleteWebGroup(c *gin.Context) {
2022-12-23 11:08:28 +08:00
var req request.WebsiteResourceReq
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
2022-11-02 18:18:20 +08:00
return
}
2022-12-23 11:08:28 +08:00
if err := websiteGroupService.DeleteGroup(req.ID); err != nil {
2022-11-02 18:18:20 +08:00
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}