2022-11-10 09:44:38 +00: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 07:26:51 +00:00
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
2022-11-10 09:44:38 +00:00
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/gin-gonic/gin"
)
2023-01-04 14:31:51 +00:00
// @Tags Website DNS
2023-01-05 03:57:03 +00:00
// @Summary Page website dns accounts
2023-01-04 14:31:51 +00: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 09:44:38 +00: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 09:41:39 +00:00
total , accounts , err := websiteDnsAccountService . Page ( req )
2022-11-10 09:44:38 +00: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 14:31:51 +00: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 09:44:38 +00:00
func ( b * BaseApi ) CreateWebsiteDnsAccount ( c * gin . Context ) {
2022-12-14 07:26:51 +00:00
var req request . WebsiteDnsAccountCreate
2022-11-10 09:44:38 +00:00
if err := c . ShouldBindJSON ( & req ) ; err != nil {
helper . ErrorWithDetail ( c , constant . CodeErrBadRequest , constant . ErrTypeInvalidParams , err )
return
}
2022-11-11 09:41:39 +00:00
if _ , err := websiteDnsAccountService . Create ( req ) ; err != nil {
2022-11-10 09:44:38 +00:00
helper . ErrorWithDetail ( c , constant . CodeErrInternalServer , constant . ErrTypeInternalServer , err )
return
}
helper . SuccessWithData ( c , nil )
}
2023-01-04 14:31:51 +00: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 09:44:38 +00:00
func ( b * BaseApi ) UpdateWebsiteDnsAccount ( c * gin . Context ) {
2022-12-14 07:26:51 +00:00
var req request . WebsiteDnsAccountUpdate
2022-11-10 09:44:38 +00:00
if err := c . ShouldBindJSON ( & req ) ; err != nil {
helper . ErrorWithDetail ( c , constant . CodeErrBadRequest , constant . ErrTypeInvalidParams , err )
return
}
2022-11-11 09:41:39 +00:00
if _ , err := websiteDnsAccountService . Update ( req ) ; err != nil {
2022-11-10 09:44:38 +00:00
helper . ErrorWithDetail ( c , constant . CodeErrInternalServer , constant . ErrTypeInternalServer , err )
return
}
helper . SuccessWithData ( c , nil )
}
2023-01-04 14:31:51 +00: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]
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFuntions":[{"input_colume":"id","input_value":"id","isList":false,"db":"website_dns_accounts","output_colume":"name","output_value":"name"}],"formatZH":"删除网站 dns [name]","formatEN":"Delete website dns [name]"}
2022-11-10 09:44:38 +00:00
func ( b * BaseApi ) DeleteWebsiteDnsAccount ( c * gin . Context ) {
2022-12-22 02:34:02 +00:00
var req request . WebsiteResourceReq
if err := c . ShouldBindJSON ( & req ) ; err != nil {
2022-11-10 09:44:38 +00:00
helper . ErrorWithDetail ( c , constant . CodeErrBadRequest , constant . ErrTypeInvalidParams , err )
return
}
2022-12-22 02:34:02 +00:00
if err := websiteDnsAccountService . Delete ( req . ID ) ; err != nil {
2022-11-10 09:44:38 +00:00
helper . ErrorWithDetail ( c , constant . CodeErrInternalServer , constant . ErrTypeInternalServer , err )
return
}
helper . SuccessWithData ( c , nil )
}