page

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Created means a Page was created.
	Created = "cms.static.page.created"

	// FieldsAdded means Fields were added to a Page.
	FieldsAdded = "cms.static.page.fields_added"

	// FieldsRemoved means Fields were removed from a Page.
	FieldsRemoved = "cms.static.page.fields_removed"
)
View Source
const Aggregate = "cms.static.page"

Aggregate is the name of the Page aggregate.

Variables

View Source
var (
	// ErrEmptyName is returned when trying to create a Page with an empty name.
	ErrEmptyName = errors.New("empty name")

	// ErrNotCreated is returned when trying to use a Page that wasn't created yet.
	ErrNotCreated = errors.New("page not created")

	// ErrDuplicateField is returned when adding a Field to a Page that already
	// has a Field with the same name.
	ErrDuplicateField = errors.New("duplicate field")

	// ErrFieldNotFound is returned when trying to get a Field of a Page that
	// doesn't exist in the Page.
	ErrFieldNotFound = errors.New("field not found")

	// ErrGuarded is retured when trying to remove a guarded Field from a Page.
	ErrGuarded = errors.New("guarded field")
)

Functions

func RegisterEvents

func RegisterEvents(r event.Registry)

RegisterEvents register events into a registry.

Types

type CreatedData

type CreatedData struct {
	Name string
}

CreatedData is the event data for Created.

type FieldsAddedData

type FieldsAddedData struct {
	Fields []field.Field
}

FieldsAddedData is the event data for FieldsAdded.

type FieldsRemovedData

type FieldsRemovedData struct {
	Fields []string
}

FieldsRemovedData is the event data for FieldsRemoved.

type Page

type Page struct {
	*aggregate.Base

	Name   string
	Fields []field.Field
}

Page is a web page.

func Create

func Create(name string, fields ...field.Field) (*Page, error)

Create creates the Page with the given name. Create(name, fields...) is a shortcut for

p := New(uuid.New())
err := p.Create("foo", fields...)

Fields passed to Create are added to the Page as guarded Fields that cannot be removed. To add removable Fields to a Page p, use p.Add instead:

p, _ := page.Create("foo")
p.Add(field.NewText(...), field.NewToggle(...))

func New

func New(id uuid.UUID) *Page

New returns a new Page. You probably want to use Create instead.

func (*Page) Add

func (p *Page) Add(fields ...field.Field) error

func (*Page) ApplyEvent

func (p *Page) ApplyEvent(evt event.Event)

ApplyEvent applies aggregate events.

func (*Page) Create

func (p *Page) Create(name string) error

Create creates the page by giving it a name.

func (*Page) Field

func (p *Page) Field(name string) (field.Field, error)

func (*Page) MarshalJSON

func (p *Page) MarshalJSON() ([]byte, error)

func (*Page) Remove

func (p *Page) Remove(fields ...string) error

func (*Page) UnmarshalJSON

func (p *Page) UnmarshalJSON(b []byte) error

type Repository

type Repository interface {
	// Save saves a Page.
	Save(context.Context, *Page) error

	// Fetch fetches the Page with the given UUID.
	Fetch(context.Context, uuid.UUID) (*Page, error)

	// Delete deletes a Page.
	Delete(context.Context, *Page) error
}

A Repository persists Pages.

func GoesRepository

func GoesRepository(repo aggregate.Repository) Repository

GoesRepository returns a Repository that uses the provided aggregate repository under the hood.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL