2022-10-28 17:04:57 +08:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2022-11-02 15:19:14 +08:00
|
|
|
func (b *BaseApi) PageWebsite(c *gin.Context) {
|
|
|
|
var req dto.WebSiteReq
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
total, websites, err := websiteService.PageWebSite(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, dto.PageResult{
|
|
|
|
Total: total,
|
|
|
|
Items: websites,
|
|
|
|
})
|
|
|
|
}
|
2022-10-28 17:04:57 +08:00
|
|
|
|
2022-11-02 15:19:14 +08:00
|
|
|
func (b *BaseApi) CreateWebsite(c *gin.Context) {
|
2022-10-28 17:04:57 +08:00
|
|
|
var req dto.WebSiteCreate
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err := websiteService.CreateWebsite(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
2022-11-02 15:19:14 +08:00
|
|
|
|
|
|
|
func (b *BaseApi) DeleteWebSite(c *gin.Context) {
|
|
|
|
var req dto.WebSiteDel
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err := websiteService.DeleteWebSite(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
2022-11-03 17:06:48 +08:00
|
|
|
|
|
|
|
func (b *BaseApi) GetWebDomains(c *gin.Context) {
|
|
|
|
|
|
|
|
websiteId, err := helper.GetIntParamByKey(c, "websiteId")
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
list, err := websiteService.GetWebsiteDomain(websiteId)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, list)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *BaseApi) DeleteWebDomain(c *gin.Context) {
|
|
|
|
|
|
|
|
id, err := helper.GetParamID(c)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := websiteService.DeleteWebsiteDomain(id); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|