2022-10-28 17:04:57 +08:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
2022-11-02 15:19:14 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
2022-10-28 17:04:57 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
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
|
|
|
|
|
|
|
func (b *BaseApi) CreateWebGroup(c *gin.Context) {
|
|
|
|
var req dto.WebSiteGroupCreate
|
|
|
|
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
|
|
|
|
|
|
|
func (b *BaseApi) UpdateWebGroup(c *gin.Context) {
|
|
|
|
var req dto.WebSiteGroupUpdate
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *BaseApi) DeleteWebGroup(c *gin.Context) {
|
|
|
|
|
2022-11-03 17:06:48 +08:00
|
|
|
groupId, err := helper.GetIntParamByKey(c, "groupId")
|
2022-11-02 18:18:20 +08:00
|
|
|
if err != nil {
|
2022-11-03 17:06:48 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
2022-11-02 18:18:20 +08:00
|
|
|
return
|
|
|
|
}
|
2022-11-03 17:06:48 +08:00
|
|
|
|
|
|
|
if err := websiteGroupService.DeleteGroup(groupId); err != nil {
|
2022-11-02 18:18:20 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|