diff --git a/application/ssl.go b/application/ssl.go index 5cc3743..8605584 100644 --- a/application/ssl.go +++ b/application/ssl.go @@ -3,6 +3,7 @@ package application import ( "autossl/domain/model" "autossl/domain/service" + "autossl/infrastructure/acme" "autossl/infrastructure/exception" "autossl/infrastructure/util" "github.com/labstack/echo/v4" @@ -74,7 +75,7 @@ func Upload(c echo.Context) error { func Download(c echo.Context) error { code := c.Param("code") - filePath := filepath.Join(service.CertPath, code) + filePath := filepath.Join(acme.CertPath, code) etag, err := service.Etag(filePath) if err != nil { @@ -87,7 +88,7 @@ func Download(c echo.Context) error { func DownloadHead(c echo.Context) error { code := c.Param("code") - filePath := filepath.Join(service.CertPath, code) + filePath := filepath.Join(acme.CertPath, code) etag, err := service.Etag(filePath) if err != nil { diff --git a/domain/repository/cert_repository.go b/domain/repository/cert_repository.go index 8345c0c..7d688c3 100644 --- a/domain/repository/cert_repository.go +++ b/domain/repository/cert_repository.go @@ -7,6 +7,7 @@ import ( type CertRepository interface { Create(cert *model.Cert) error FindByDomain(domain string) (*model.Cert, error) + FindByCode(code string) (*model.Cert, error) List() ([]*model.Cert, error) Delete(code string) error } diff --git a/domain/service/cert_service.go b/domain/service/cert_service.go index 97c0e16..a7ce886 100644 --- a/domain/service/cert_service.go +++ b/domain/service/cert_service.go @@ -100,10 +100,17 @@ func ListCert() ([]*model.Cert, error) { } func DeleteCert(code string) error { + var err error repo := &repository.CertRepo{ Db: database.Init(), } - err := repo.Delete(code) + + byCode, err := repo.FindByCode(code) + if err != nil { + return err + } + + err = acme.Remove(byCode.Domain) if err != nil { return err } @@ -113,6 +120,11 @@ func DeleteCert(code string) error { return err } + err = repo.Delete(code) + if err != nil { + return err + } + return nil } diff --git a/infrastructure/repository/cert_repository.go b/infrastructure/repository/cert_repository.go index 9072bed..2a6c057 100644 --- a/infrastructure/repository/cert_repository.go +++ b/infrastructure/repository/cert_repository.go @@ -29,6 +29,14 @@ func (repo *CertRepo) FindByDomain(domain string) (*model.Cert, error) { return ToModelCert(first), err } +func (repo *CertRepo) FindByCode(code string) (*model.Cert, error) { + first, err := repo.Db.Cert.Query().Where(cert.CodeEQ(code)).Only(context.Background()) + if err != nil { + return nil, err + } + return ToModelCert(first), err +} + func (repo *CertRepo) List() ([]*model.Cert, error) { q := repo.Db.Cert.Query(). Order(ent.Desc(cert.FieldCreatedAt))