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

122 lines
4.2 KiB
Go
Raw Normal View History

2022-10-17 09:10:06 +08:00
package v1
import (
2022-10-18 18:39:45 +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-10-17 09:10:06 +08:00
"github.com/gin-gonic/gin"
)
2023-01-04 22:31:51 +08:00
// @Tags Container Compose-template
// @Summary Create compose template
2023-01-04 22:31:51 +08:00
// @Description 创建容器编排模版
// @Accept json
// @Param request body dto.ComposeTemplateCreate true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /containers/template [post]
2023-10-07 15:46:44 +08:00
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"创建 compose 模版 [name]","formatEN":"create compose template [name]"}
2022-10-17 09:10:06 +08:00
func (b *BaseApi) CreateComposeTemplate(c *gin.Context) {
var req dto.ComposeTemplateCreate
2023-10-27 14:19:26 +08:00
if err := helper.CheckBindAndValidate(&req, c); err != nil {
2022-10-17 09:10:06 +08:00
return
}
2023-10-27 14:19:26 +08:00
2022-10-17 09:10:06 +08:00
if err := composeTemplateService.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 Container Compose-template
// @Summary Page compose templates
2023-01-04 22:31:51 +08:00
// @Description 获取容器编排模版列表分页
// @Accept json
2023-02-07 18:48:32 +08:00
// @Param request body dto.SearchWithPage true "request"
2023-01-04 22:31:51 +08:00
// @Produce json
// @Success 200 {object} dto.PageResult
// @Security ApiKeyAuth
// @Router /containers/template/search [post]
2022-10-17 09:10:06 +08:00
func (b *BaseApi) SearchComposeTemplate(c *gin.Context) {
2023-02-07 18:48:32 +08:00
var req dto.SearchWithPage
2023-10-27 14:19:26 +08:00
if err := helper.CheckBindAndValidate(&req, c); err != nil {
2022-10-17 09:10:06 +08:00
return
}
total, list, err := composeTemplateService.SearchWithPage(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, dto.PageResult{
Items: list,
Total: total,
})
}
2023-01-04 22:31:51 +08:00
// @Tags Container Compose-template
// @Summary List compose templates
2023-01-04 22:31:51 +08:00
// @Description 获取容器编排模版列表
// @Produce json
// @Success 200 {array} dto.ComposeTemplateInfo
2023-01-04 22:31:51 +08:00
// @Security ApiKeyAuth
// @Router /containers/template [get]
2022-10-17 09:10:06 +08:00
func (b *BaseApi) ListComposeTemplate(c *gin.Context) {
list, err := composeTemplateService.List()
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, list)
}
2023-01-04 22:31:51 +08:00
// @Tags Container Compose-template
// @Summary Delete compose template
// @Description 删除容器编排模版
// @Accept json
// @Param request body dto.BatchDelete true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /containers/template/del [post]
2023-10-07 15:46:44 +08:00
// @x-panel-log {"bodyKeys":["ids"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"ids","isList":true,"db":"compose_templates","output_column":"name","output_value":"names"}],"formatZH":"删除 compose 模版 [names]","formatEN":"delete compose template [names]"}
2022-10-17 09:10:06 +08:00
func (b *BaseApi) DeleteComposeTemplate(c *gin.Context) {
var req dto.BatchDeleteReq
2023-10-27 14:19:26 +08:00
if err := helper.CheckBindAndValidate(&req, c); err != nil {
2022-10-17 09:10:06 +08:00
return
}
if err := composeTemplateService.Delete(req.Ids); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}
2023-01-04 22:31:51 +08:00
// @Tags Container Compose-template
// @Summary Update compose template
// @Description 更新容器编排模版
// @Accept json
// @Param request body dto.ComposeTemplateUpdate true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /containers/template/update [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":"compose_templates","output_column":"name","output_value":"name"}],"formatZH":"更新 compose 模版 [name]","formatEN":"update compose template information [name]"}
2022-10-17 09:10:06 +08:00
func (b *BaseApi) UpdateComposeTemplate(c *gin.Context) {
var req dto.ComposeTemplateUpdate
2023-10-27 14:19:26 +08:00
if err := helper.CheckBindAndValidate(&req, c); err != nil {
2022-10-17 09:10:06 +08:00
return
}
upMap := make(map[string]interface{})
upMap["content"] = req.Content
upMap["description"] = req.Description
if err := composeTemplateService.Update(req.ID, upMap); err != nil {
2022-10-17 09:10:06 +08:00
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}