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"
)
2023-01-04 22:31:51 +08:00
// @Tags Website DNS
2023-01-05 11:57:03 +08:00
// @Summary Page website dns accounts
2023-01-04 22:31:51 +08:00
// @Description 获取网站 dns 列表分页
// @Accept json
// @Param request body dto.PageInfo true "request"
// @Success 200 {object} dto.PageResult
// @Security ApiKeyAuth
// @Router /websites/dns/search [post]
2022-11-10 17:44:38 +08:00
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 ,
} )
}
2023-01-04 22:31:51 +08:00
// @Tags Website DNS
// @Summary Create website dns account
// @Description 创建网站 dns
// @Accept json
// @Param request body request.WebsiteDnsAccountCreate true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /websites/dns [post]
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"创建网站 dns [name]","formatEN":"Create website dns [name]"}
2022-11-10 17:44:38 +08:00
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 )
}
2023-01-04 22:31:51 +08:00
// @Tags Website DNS
// @Summary Update website dns account
// @Description 更新网站 dns
// @Accept json
// @Param request body request.WebsiteDnsAccountUpdate true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /websites/dns/update [post]
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"更新网站 dns [name]","formatEN":"Update website dns [name]"}
2022-11-10 17:44:38 +08:00
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 )
}
2023-01-04 22:31:51 +08:00
// @Tags Website DNS
// @Summary Delete website dns account
// @Description 删除网站 dns
// @Accept json
// @Param request body request.WebsiteResourceReq true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /websites/dns/del [post]
2023-05-30 15:30:57 +08:00
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFuntions":[{"input_column":"id","input_value":"id","isList":false,"db":"website_dns_accounts","output_column":"name","output_value":"name"}],"formatZH":"删除网站 dns [name]","formatEN":"Delete website dns [name]"}
2022-11-10 17:44:38 +08:00
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 )
}