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

119 lines
3.6 KiB
Go
Raw Normal View History

2022-11-11 17:41:39 +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-11 17:41:39 +08:00
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/gin-gonic/gin"
2022-11-20 18:32:56 +08:00
"reflect"
2022-11-11 17:41:39 +08:00
)
func (b *BaseApi) PageWebsiteSSL(c *gin.Context) {
2022-12-14 15:26:51 +08:00
var req request.WebsiteSSLSearch
2022-11-11 17:41:39 +08:00
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
2022-11-20 18:32:56 +08:00
if !reflect.DeepEqual(req.PageInfo, dto.PageInfo{}) {
total, accounts, err := websiteSSLService.Page(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, dto.PageResult{
Total: total,
Items: accounts,
})
} else {
list, err := websiteSSLService.Search()
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, list)
2022-11-11 17:41:39 +08:00
}
}
2022-11-16 10:31:35 +08:00
func (b *BaseApi) CreateWebsiteSSL(c *gin.Context) {
2022-12-14 15:26:51 +08:00
var req request.WebsiteSSLCreate
2022-11-16 10:31:35 +08:00
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
res, err := websiteSSLService.Create(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, res)
}
func (b *BaseApi) RenewWebsiteSSL(c *gin.Context) {
2022-12-14 15:26:51 +08:00
var req request.WebsiteSSLRenew
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
if err := websiteSSLService.Renew(req.SSLID); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}
2022-11-16 10:31:35 +08:00
func (b *BaseApi) GetDNSResolve(c *gin.Context) {
2022-12-14 15:26:51 +08:00
var req request.WebsiteDNSReq
2022-11-16 10:31:35 +08:00
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
res, err := websiteSSLService.GetDNSResolve(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, res)
}
func (b *BaseApi) DeleteWebsiteSSL(c *gin.Context) {
2022-12-23 11:08:28 +08:00
var req request.WebsiteResourceReq
if err := c.ShouldBindJSON(&req); err != nil {
2022-11-16 10:31:35 +08:00
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
2022-12-23 11:08:28 +08:00
if err := websiteSSLService.Delete(req.ID); err != nil {
2022-11-16 10:31:35 +08:00
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}
2022-12-29 14:55:20 +08:00
func (b *BaseApi) GetWebsiteSSLByWebsiteId(c *gin.Context) {
websiteId, err := helper.GetIntParamByKey(c, "websiteId")
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
websiteSSL, err := websiteSSLService.GetWebsiteSSL(websiteId)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, websiteSSL)
}
2022-12-29 14:55:20 +08:00
func (b *BaseApi) GetWebsiteSSLById(c *gin.Context) {
id, err := helper.GetParamID(c)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
websiteSSL, err := websiteSSLService.GetSSL(id)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, websiteSSL)
}