refactor: clean code

This commit is contained in:
Fu Diwei
2025-01-18 22:18:47 +08:00
parent 3e1ecd60a1
commit ce4c590b1c
20 changed files with 108 additions and 93 deletions

View File

@@ -5,6 +5,8 @@ import (
"time"
)
const CollectionNameAccess = "access"
type Access struct {
Meta
Name string `json:"name" db:"name"`

View File

@@ -4,6 +4,8 @@ import (
"github.com/go-acme/lego/v4/registration"
)
const CollectionNameAcmeAccount = "acme_accounts"
type AcmeAccount struct {
Meta
CA string `json:"ca" db:"ca"`

View File

@@ -2,12 +2,7 @@ package domain
import "time"
type CertificateSourceType string
const (
CertificateSourceTypeWorkflow = CertificateSourceType("workflow")
CertificateSourceTypeUpload = CertificateSourceType("upload")
)
const CollectionNameCertificate = "certificate"
type Certificate struct {
Meta
@@ -26,6 +21,13 @@ type Certificate struct {
DeletedAt *time.Time `json:"deleted" db:"deleted"`
}
type CertificateSourceType string
const (
CertificateSourceTypeWorkflow = CertificateSourceType("workflow")
CertificateSourceTypeUpload = CertificateSourceType("upload")
)
type CertificateArchiveFileReq struct {
CertificateId string `json:"-"`
Format string `json:"format"`

View File

@@ -5,6 +5,8 @@ import (
"fmt"
)
const CollectionNameSettings = "settings"
type Settings struct {
Meta
Name string `json:"name" db:"name"`

View File

@@ -6,6 +6,23 @@ import (
"github.com/usual2970/certimate/internal/pkg/utils/maps"
)
const CollectionNameWorkflow = "workflow"
type Workflow struct {
Meta
Name string `json:"name" db:"name"`
Description string `json:"description" db:"description"`
Trigger WorkflowTriggerType `json:"trigger" db:"trigger"`
TriggerCron string `json:"triggerCron" db:"triggerCron"`
Enabled bool `json:"enabled" db:"enabled"`
Content *WorkflowNode `json:"content" db:"content"`
Draft *WorkflowNode `json:"draft" db:"draft"`
HasDraft bool `json:"hasDraft" db:"hasDraft"`
LastRunId string `json:"lastRunId" db:"lastRunId"`
LastRunStatus WorkflowRunStatusType `json:"lastRunStatus" db:"lastRunStatus"`
LastRunTime time.Time `json:"lastRunTime" db:"lastRunTime"`
}
type WorkflowNodeType string
const (
@@ -25,25 +42,6 @@ const (
WorkflowTriggerTypeManual = WorkflowTriggerType("manual")
)
type Workflow struct {
Meta
Name string `json:"name" db:"name"`
Description string `json:"description" db:"description"`
Trigger WorkflowTriggerType `json:"trigger" db:"trigger"`
TriggerCron string `json:"triggerCron" db:"triggerCron"`
Enabled bool `json:"enabled" db:"enabled"`
Content *WorkflowNode `json:"content" db:"content"`
Draft *WorkflowNode `json:"draft" db:"draft"`
HasDraft bool `json:"hasDraft" db:"hasDraft"`
LastRunId string `json:"lastRunId" db:"lastRunId"`
LastRunStatus WorkflowRunStatusType `json:"lastRunStatus" db:"lastRunStatus"`
LastRunTime time.Time `json:"lastRunTime" db:"lastRunTime"`
}
func (w *Workflow) Table() string {
return "workflow"
}
type WorkflowNode struct {
Id string `json:"id"`
Type WorkflowNodeType `json:"type"`
@@ -151,6 +149,12 @@ type WorkflowNodeIOValueSelector struct {
Name string `json:"name"`
}
type WorkflowNodeIONameType = string
const (
WorkflowNodeIONameCertificate WorkflowNodeIONameType = "certificate"
)
type WorkflowRunReq struct {
WorkflowId string `json:"-"`
Trigger WorkflowTriggerType `json:"trigger"`

View File

@@ -1,5 +1,7 @@
package domain
const CollectionNameWorkflowOutput = "workflow_output"
type WorkflowOutput struct {
Meta
WorkflowId string `json:"workflowId" db:"workflow"`
@@ -8,5 +10,3 @@ type WorkflowOutput struct {
Outputs []WorkflowNodeIO `json:"outputs" db:"outputs"`
Succeeded bool `json:"succeeded" db:"succeeded"`
}
const WORKFLOW_OUTPUT_CERTIFICATE = "certificate"

View File

@@ -2,14 +2,7 @@ package domain
import "time"
type WorkflowRunStatusType string
const (
WorkflowRunStatusTypePending WorkflowRunStatusType = "pending"
WorkflowRunStatusTypeRunning WorkflowRunStatusType = "running"
WorkflowRunStatusTypeSucceeded WorkflowRunStatusType = "succeeded"
WorkflowRunStatusTypeFailed WorkflowRunStatusType = "failed"
)
const CollectionNameWorkflowRun = "workflow_run"
type WorkflowRun struct {
Meta
@@ -22,6 +15,15 @@ type WorkflowRun struct {
Error string `json:"error" db:"error"`
}
type WorkflowRunStatusType string
const (
WorkflowRunStatusTypePending WorkflowRunStatusType = "pending"
WorkflowRunStatusTypeRunning WorkflowRunStatusType = "running"
WorkflowRunStatusTypeSucceeded WorkflowRunStatusType = "succeeded"
WorkflowRunStatusTypeFailed WorkflowRunStatusType = "failed"
)
type WorkflowRunLog struct {
NodeId string `json:"nodeId"`
NodeName string `json:"nodeName"`