refactor: clean code

This commit is contained in:
Fu Diwei
2025-01-05 00:08:12 +08:00
parent 3b9a7fe805
commit 61843a4997
69 changed files with 972 additions and 839 deletions

View File

@@ -14,11 +14,13 @@ func NewCertificateRepository() *CertificateRepository {
}
func (c *CertificateRepository) ListExpireSoon(ctx context.Context) ([]domain.Certificate, error) {
rs := []domain.Certificate{}
if err := app.GetApp().Dao().DB().
certificates := []domain.Certificate{}
err := app.GetApp().Dao().DB().
NewQuery("SELECT * FROM certificate WHERE expireAt > DATETIME('now') AND expireAt < DATETIME('now', '+20 days')").
All(&rs); err != nil {
All(&certificates)
if err != nil {
return nil, err
}
return rs, nil
return certificates, nil
}

View File

@@ -20,7 +20,7 @@ func (s *SettingsRepository) GetByName(ctx context.Context, name string) (*domai
return nil, err
}
rs := &domain.Settings{
settings := &domain.Settings{
Meta: domain.Meta{
Id: record.GetId(),
CreatedAt: record.GetCreated().Time(),
@@ -29,6 +29,5 @@ func (s *SettingsRepository) GetByName(ctx context.Context, name string) (*domai
Name: record.GetString("name"),
Content: record.GetString("content"),
}
return rs, nil
return settings, nil
}

View File

@@ -15,6 +15,7 @@ func NewStatisticsRepository() *StatisticsRepository {
func (r *StatisticsRepository) Get(ctx context.Context) (*domain.Statistics, error) {
rs := &domain.Statistics{}
// 所有证书
certTotal := struct {
Total int `db:"total"`

View File

@@ -82,7 +82,7 @@ func (w *WorkflowRepository) SaveRun(ctx context.Context, run *domain.WorkflowRu
return nil
}
func (w *WorkflowRepository) Get(ctx context.Context, id string) (*domain.Workflow, error) {
func (w *WorkflowRepository) GetById(ctx context.Context, id string) (*domain.Workflow, error) {
record, err := app.GetApp().Dao().FindRecordById("workflow", id)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {

View File

@@ -17,7 +17,7 @@ func NewWorkflowOutputRepository() *WorkflowOutputRepository {
return &WorkflowOutputRepository{}
}
func (w *WorkflowOutputRepository) Get(ctx context.Context, nodeId string) (*domain.WorkflowOutput, error) {
func (w *WorkflowOutputRepository) GetByNodeId(ctx context.Context, nodeId string) (*domain.WorkflowOutput, error) {
records, err := app.GetApp().Dao().FindRecordsByFilter("workflow_output", "nodeId={:nodeId}", "-created", 1, 0, dbx.Params{"nodeId": nodeId})
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
@@ -56,7 +56,7 @@ func (w *WorkflowOutputRepository) Get(ctx context.Context, nodeId string) (*dom
return rs, nil
}
func (w *WorkflowOutputRepository) GetCertificate(ctx context.Context, nodeId string) (*domain.Certificate, error) {
func (w *WorkflowOutputRepository) GetCertificateByNodeId(ctx context.Context, nodeId string) (*domain.Certificate, error) {
records, err := app.GetApp().Dao().FindRecordsByFilter("certificate", "workflowNodeId={:workflowNodeId}", "-created", 1, 0, dbx.Params{"workflowNodeId": nodeId})
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
@@ -83,8 +83,8 @@ func (w *WorkflowOutputRepository) GetCertificate(ctx context.Context, nodeId st
IssuerCertificate: record.GetString("issuerCertificate"),
EffectAt: record.GetTime("effectAt"),
ExpireAt: record.GetTime("expireAt"),
AcmeCertUrl: record.GetString("acmeCertUrl"),
AcmeCertStableUrl: record.GetString("acmeCertStableUrl"),
ACMECertUrl: record.GetString("acmeCertUrl"),
ACMECertStableUrl: record.GetString("acmeCertStableUrl"),
WorkflowId: record.GetString("workflowId"),
WorkflowNodeId: record.GetString("workflowNodeId"),
WorkflowOutputId: record.GetString("workflowOutputId"),
@@ -137,8 +137,8 @@ func (w *WorkflowOutputRepository) Save(ctx context.Context, output *domain.Work
certRecord.Set("issuerCertificate", certificate.IssuerCertificate)
certRecord.Set("effectAt", certificate.EffectAt)
certRecord.Set("expireAt", certificate.ExpireAt)
certRecord.Set("acmeCertUrl", certificate.AcmeCertUrl)
certRecord.Set("acmeCertStableUrl", certificate.AcmeCertStableUrl)
certRecord.Set("acmeCertUrl", certificate.ACMECertUrl)
certRecord.Set("acmeCertStableUrl", certificate.ACMECertStableUrl)
certRecord.Set("workflowId", certificate.WorkflowId)
certRecord.Set("workflowNodeId", certificate.WorkflowNodeId)
certRecord.Set("workflowOutputId", certificate.WorkflowOutputId)
@@ -149,7 +149,7 @@ func (w *WorkflowOutputRepository) Save(ctx context.Context, output *domain.Work
// 更新 certificate
for i, item := range output.Outputs {
if item.Name == "certificate" {
if item.Name == domain.WORKFLOW_OUTPUT_CERTIFICATE {
output.Outputs[i].Value = certRecord.GetId()
break
}