2022-11-10 17:44:38 +08:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
2022-12-14 15:26:51 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
2022-11-10 17:44:38 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (b *BaseApi) PageWebsiteDnsAccount(c *gin.Context) {
|
|
|
|
var req dto.PageInfo
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
2022-11-11 17:41:39 +08:00
|
|
|
total, accounts, err := websiteDnsAccountService.Page(req)
|
2022-11-10 17:44:38 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, dto.PageResult{
|
|
|
|
Total: total,
|
|
|
|
Items: accounts,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *BaseApi) CreateWebsiteDnsAccount(c *gin.Context) {
|
2022-12-14 15:26:51 +08:00
|
|
|
var req request.WebsiteDnsAccountCreate
|
2022-11-10 17:44:38 +08:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
2022-11-11 17:41:39 +08:00
|
|
|
if _, err := websiteDnsAccountService.Create(req); err != nil {
|
2022-11-10 17:44:38 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *BaseApi) UpdateWebsiteDnsAccount(c *gin.Context) {
|
2022-12-14 15:26:51 +08:00
|
|
|
var req request.WebsiteDnsAccountUpdate
|
2022-11-10 17:44:38 +08:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
2022-11-11 17:41:39 +08:00
|
|
|
if _, err := websiteDnsAccountService.Update(req); err != nil {
|
2022-11-10 17:44:38 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *BaseApi) DeleteWebsiteDnsAccount(c *gin.Context) {
|
2022-12-22 10:34:02 +08:00
|
|
|
var req request.WebsiteResourceReq
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
2022-11-10 17:44:38 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-22 10:34:02 +08:00
|
|
|
if err := websiteDnsAccountService.Delete(req.ID); err != nil {
|
2022-11-10 17:44:38 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|