mirror of
https://github.com/tnb-labs/panel.git
synced 2026-09-17 16:39:01 +08:00
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
103 lines
2.2 KiB
Go
103 lines
2.2 KiB
Go
package service
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/libtnb/chix/v2"
|
|
"github.com/samber/do/v2"
|
|
|
|
"github.com/acepanel/panel/v3/internal/biz"
|
|
"github.com/acepanel/panel/v3/internal/request"
|
|
)
|
|
|
|
type CertDNSService struct {
|
|
certDNSRepo *biz.CertDNSUsecase
|
|
}
|
|
|
|
func NewCertDNSService(i do.Injector) (*CertDNSService, error) {
|
|
return &CertDNSService{
|
|
certDNSRepo: do.MustInvoke[*biz.CertDNSUsecase](i),
|
|
}, nil
|
|
}
|
|
|
|
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(r.Context(), 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(r.Context(), 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(r.Context(), req.ID); err != nil {
|
|
Error(w, http.StatusInternalServerError, "%v", err)
|
|
return
|
|
}
|
|
|
|
Success(w, nil)
|
|
}
|