Documentation
¶
Overview ¶
Package segments is the Segment domain module: named Conditions on Contacts, with the rows they select and the live work that uses them.
Index ¶
- Variables
- func UsingTag(ctx context.Context, s *ent.Scoped, name string) ([]*ent.Segment, error)
- type CreateInput
- type Module
- func (s *Module) Archive(ctx context.Context, ws *ent.Scoped, id int64) error
- func (s *Module) Contacts(ctx context.Context, ws *ent.Scoped, id int64, p pagination.Params) (pagination.Page[*ent.Contact], error)
- func (s *Module) Count(ctx context.Context, ws *ent.Scoped, id int64) (int, error)
- func (s *Module) Create(ctx context.Context, ws *ent.Scoped, in CreateInput) (*ent.Segment, error)
- func (s *Module) Get(ctx context.Context, ws *ent.Scoped, id int64) (*ent.Segment, error)
- func (s *Module) List(ctx context.Context, ws *ent.Scoped, p pagination.Params, archived bool) (pagination.Page[*ent.Segment], error)
- func (s *Module) Preview(ctx context.Context, ws *ent.Scoped, cond string) (int, error)
- func (s *Module) Unarchive(ctx context.Context, ws *ent.Scoped, id int64) error
- func (s *Module) Update(ctx context.Context, ws *ent.Scoped, id int64, in UpdateInput) (*ent.Segment, error)
- func (s *Module) Validate(ctx context.Context, ws *ent.Scoped, cond string) error
- type UpdateInput
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidCondition: the condition does not parse or does not fit the // Contact schema. The wrapped message is safe to show to the author. ErrInvalidCondition = validation.Refuse("segments: invalid condition", "errors.segment_condition_invalid") // ErrNotFound: no such Segment in this Workspace. ErrNotFound = validation.Refuse("segments: segment not found", "errors.segment_not_found") )
Domain errors returned by Module. Callers match with errors.Is.
Functions ¶
Types ¶
type CreateInput ¶
CreateInput is a new Segment. A nil or empty Condition means "no rules yet".
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module is the one place a Segment is written, validated, previewed and counted (ADR 0016). Create and update share one validation rule set; handlers stay thin adapters (scope check, call, map). Membership is the rule alone — Send-eligibility is subtracted only at send, never folded into a count (ADR 0001).
func New ¶
New builds the Segments module. It holds no client: every call takes the Workspace's scoped client (ADR 0017); the bus runs the archive in one transaction.
func (*Module) Archive ¶
Archive discards a Segment (ADR 0049), unless a draft or scheduled Broadcast uses it: then it returns an *inuse.Error naming those Broadcasts. A sent or failed Broadcast keeps its stored reference as history and does not block. A missing Segment is ErrNotFound; archiving an archived one changes nothing.
func (*Module) Contacts ¶
func (s *Module) Contacts(ctx context.Context, ws *ent.Scoped, id int64, p pagination.Params) (pagination.Page[*ent.Contact], error)
Contacts returns one page of the Contacts a stored Segment matches, evaluated live, ascending by id.
func (*Module) List ¶
func (s *Module) List(ctx context.Context, ws *ent.Scoped, p pagination.Params, archived bool) (pagination.Page[*ent.Segment], error)
List returns one page of the Workspace's Segments, ascending by id: the kept ones, or with archived the archived ones.
func (*Module) Preview ¶
Preview counts the Contacts in the Workspace that match an unsaved condition.
func (*Module) Unarchive ¶
Unarchive brings an archived Segment back to the lists. Restoring one that is not archived changes nothing; a missing Segment is ErrNotFound.
func (*Module) Update ¶
func (s *Module) Update(ctx context.Context, ws *ent.Scoped, id int64, in UpdateInput) (*ent.Segment, error)
Update validates a changed condition exactly as Create does, then applies the change.
type UpdateInput ¶
UpdateInput changes a Segment; nil fields are left as they are.