feat: mail service
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
// Package template defines the logical template entity used by the
|
||||
// filesystem-backed Mail Service template catalog.
|
||||
package template
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"galaxy/mail/internal/domain/common"
|
||||
)
|
||||
|
||||
// Template stores one locale-specific template bundle.
|
||||
type Template struct {
|
||||
// TemplateID identifies the template family.
|
||||
TemplateID common.TemplateID
|
||||
|
||||
// Locale stores the canonical locale of the template variant.
|
||||
Locale common.Locale
|
||||
|
||||
// SubjectTemplate stores the subject template source.
|
||||
SubjectTemplate string
|
||||
|
||||
// TextTemplate stores the plaintext body template source.
|
||||
TextTemplate string
|
||||
|
||||
// HTMLTemplate stores the optional HTML body template source.
|
||||
HTMLTemplate string
|
||||
|
||||
// Version stores the template version marker projected into the domain
|
||||
// model.
|
||||
Version string
|
||||
}
|
||||
|
||||
// Validate reports whether Template satisfies the frozen Stage 2 structural
|
||||
// invariants.
|
||||
func (record Template) Validate() error {
|
||||
if err := record.TemplateID.Validate(); err != nil {
|
||||
return fmt.Errorf("template id: %w", err)
|
||||
}
|
||||
if err := record.Locale.Validate(); err != nil {
|
||||
return fmt.Errorf("template locale: %w", err)
|
||||
}
|
||||
if record.SubjectTemplate == "" {
|
||||
return fmt.Errorf("template subject template must not be empty")
|
||||
}
|
||||
if record.TextTemplate == "" {
|
||||
return fmt.Errorf("template text template must not be empty")
|
||||
}
|
||||
if err := validateToken("template version", record.Version); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateToken(name string, value string) error {
|
||||
switch {
|
||||
case strings.TrimSpace(value) == "":
|
||||
return fmt.Errorf("%s must not be empty", name)
|
||||
case strings.TrimSpace(value) != value:
|
||||
return fmt.Errorf("%s must not contain surrounding whitespace", name)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user