mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 05:31:44 +08:00
102 lines
2.1 KiB
Go
102 lines
2.1 KiB
Go
package service
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-rat/chix"
|
|
|
|
"github.com/tnb-labs/panel/internal/biz"
|
|
"github.com/tnb-labs/panel/internal/http/request"
|
|
)
|
|
|
|
type CertDNSService struct {
|
|
certDNSRepo biz.CertDNSRepo
|
|
}
|
|
|
|
func NewCertDNSService(certDNS biz.CertDNSRepo) *CertDNSService {
|
|
return &CertDNSService{
|
|
certDNSRepo: certDNS,
|
|
}
|
|
}
|
|
|
|
func (s *CertDNSService) List(w http.ResponseWriter, r *http.Request) {
|
|
req, err := Bind[request.Paginate](r)
|
|
if err != nil {
|
|
Error(w, http.StatusUnprocessableEntity, "%v", err)
|
|
return
|
|
}
|
|
|
|
certDNS, total, err := s.certDNSRepo.List(req.Page, req.Limit)
|
|
if err != nil {
|
|
Error(w, http.StatusInternalServerError, "%v", err)
|
|
return
|
|
}
|
|
|
|
Success(w, chix.M{
|
|
"total": total,
|
|
"items": certDNS,
|
|
})
|
|
}
|
|
|
|
func (s *CertDNSService) Create(w http.ResponseWriter, r *http.Request) {
|
|
req, err := Bind[request.CertDNSCreate](r)
|
|
if err != nil {
|
|
Error(w, http.StatusUnprocessableEntity, "%v", err)
|
|
return
|
|
}
|
|
|
|
certDNS, err := s.certDNSRepo.Create(req)
|
|
if err != nil {
|
|
Error(w, http.StatusInternalServerError, "%v", err)
|
|
return
|
|
}
|
|
|
|
Success(w, certDNS)
|
|
}
|
|
|
|
func (s *CertDNSService) Update(w http.ResponseWriter, r *http.Request) {
|
|
req, err := Bind[request.CertDNSUpdate](r)
|
|
if err != nil {
|
|
Error(w, http.StatusUnprocessableEntity, "%v", err)
|
|
return
|
|
}
|
|
|
|
if err = s.certDNSRepo.Update(req); err != nil {
|
|
Error(w, http.StatusInternalServerError, "%v", err)
|
|
return
|
|
}
|
|
|
|
Success(w, nil)
|
|
}
|
|
|
|
func (s *CertDNSService) Get(w http.ResponseWriter, r *http.Request) {
|
|
req, err := Bind[request.ID](r)
|
|
if err != nil {
|
|
Error(w, http.StatusUnprocessableEntity, "%v", err)
|
|
return
|
|
}
|
|
|
|
certDNS, err := s.certDNSRepo.Get(req.ID)
|
|
if err != nil {
|
|
Error(w, http.StatusInternalServerError, "%v", err)
|
|
return
|
|
}
|
|
|
|
Success(w, certDNS)
|
|
}
|
|
|
|
func (s *CertDNSService) Delete(w http.ResponseWriter, r *http.Request) {
|
|
req, err := Bind[request.ID](r)
|
|
if err != nil {
|
|
Error(w, http.StatusUnprocessableEntity, "%v", err)
|
|
return
|
|
}
|
|
|
|
if err = s.certDNSRepo.Delete(req.ID); err != nil {
|
|
Error(w, http.StatusInternalServerError, "%v", err)
|
|
return
|
|
}
|
|
|
|
Success(w, nil)
|
|
}
|