Documentation
¶
Overview ¶
Package templates is the one place an email Template is listed, read, written and deleted. Handlers on /site and /api stay thin adapters: scope check, call, map. Transactional send reads a Template through Get, by reference (ADR 0005); copy-at-author-time (ADR 0003) is marketing only and lives elsewhere.
Index ¶
- Variables
- type CreateInput
- type Module
- func (m *Module) Create(ctx context.Context, s *ent.Scoped, in CreateInput) (*ent.EmailTemplate, error)
- func (m *Module) Delete(ctx context.Context, s *ent.Scoped, id int64) error
- func (m *Module) Get(ctx context.Context, s *ent.Scoped, id int64) (*ent.EmailTemplate, error)
- func (m *Module) List(ctx context.Context, s *ent.Scoped, p pagination.Params) (pagination.Page[*ent.EmailTemplate], error)
- func (m *Module) Update(ctx context.Context, s *ent.Scoped, id int64, in UpdateInput) (*ent.EmailTemplate, error)
- type UpdateInput
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound: no such Template in this Workspace. ErrNotFound = validation.Refuse("templates: template not found", "errors.template_not_found") // ErrBlankName: the Template name is blank. ErrBlankName = validation.Refuse("templates: name must not be empty", "errors.name_empty") // ErrBodyAndDoc: a write carries both a body and a document. A client writes one of them: the // document (the server builds the body from it) or the body (which clears the document). ErrBodyAndDoc = validation.Refuse("templates: write a body or a doc, not both", "errors.body_and_doc") )
Domain errors. Callers match with errors.Is.
Functions ¶
This section is empty.
Types ¶
type CreateInput ¶
type CreateInput struct {
Name string
Subject *string
Body *string
// Doc is the editor's JSON document, empty when the Template is written as HTML. The body is
// built from it in the same save (ADR 0040).
Doc json.RawMessage
// Prepared is Doc already rendered by emailrender.FromDocument, for a caller that renders
// before it opens a transaction so that no database connection is held through the render.
// Nil renders Doc here; a Body is never combined with it.
Prepared *emailrender.Authored
}
CreateInput is a new Template; nil Subject and Body keep their defaults.
type Module ¶
type Module struct{}
Module holds no state: every call receives the Workspace-scoped client (ADR 0017).
func (*Module) Create ¶
func (m *Module) Create(ctx context.Context, s *ent.Scoped, in CreateInput) (*ent.EmailTemplate, error)
Create stores a Template. A blank name is ErrBlankName; a subject, body or document that cannot render is emailrender.ErrInvalidContent; the body is stored sanitized.
func (*Module) List ¶
func (m *Module) List(ctx context.Context, s *ent.Scoped, p pagination.Params) (pagination.Page[*ent.EmailTemplate], error)
List returns a page of the Workspace's Templates, ascending by id (a catalogue).
type UpdateInput ¶
type UpdateInput struct {
Name *string
Subject *string
Body *string
Doc json.RawMessage
}
UpdateInput changes a Template; nil fields are left as they are. A Doc is rendered to the body in the same save and stored with it; a Body alone clears the stored document, so the two never disagree.