todo

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2022 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// CreateCommand is the type for the Create command.
	CreateCommand = eh.CommandType("todolist:create")
	// DeleteCommand is the type for the Delete command.
	DeleteCommand = eh.CommandType("todolist:delete")

	// AddItemCommand is the type for the AddItem command.
	AddItemCommand = eh.CommandType("todolist:add_item")
	// RemoveItemCommand is the type for the RemoveItem command.
	RemoveItemCommand = eh.CommandType("todolist:remove_item")
	// RemoveCompletedItemsCommand is the type for the RemoveCompletedItems command.
	RemoveCompletedItemsCommand = eh.CommandType("todolist:remove_completed_items")

	// SetItemDescriptionCommand is the type for the SetItemDescription command.
	SetItemDescriptionCommand = eh.CommandType("todolist:set_item_description")
	// CheckItemCommand is the type for the CheckItem command.
	CheckItemCommand = eh.CommandType("todolist:check_item")
	// CheckAllItemsCommand is the type for the CheckAllItems command.
	CheckAllItemsCommand = eh.CommandType("todolist:check_all_items")
)
View Source
const (
	// Created is the event after a todo list is created.
	Created = eh.EventType("todolist:created")
	// Deleted is the event after a todo list is deleted.
	Deleted = eh.EventType("todolist:deleted")

	// ItemAdded is the event after a todo item is added.
	ItemAdded = eh.EventType("todolist:item_added")
	// ItemRemoved is the event after a todo item is removed.
	ItemRemoved = eh.EventType("todolist:item_removed")

	// ItemDescriptionSet is the event after a todo item's description is set.
	ItemDescriptionSet = eh.EventType("todolist:item_description_set")
	// ItemChecked is the event after a todo item's checked status is changed.
	ItemChecked = eh.EventType("todolist:item_checked")
)
View Source
const AggregateType = eh.AggregateType("todolist")

AggregateType is the aggregate type for the todo list.

Variables

View Source
var TimeNow = time.Now

TimeNow is a mockable version of time.Now.

Functions

func SetupDomain

func SetupDomain(
	commandBus *bus.CommandHandler,
	eventStore eh.EventStore,
	local HandlerAdder,
	repo eh.ReadWriteRepo,
) error

SetupDomain sets up the Todo domain.

Types

type AddItem

type AddItem struct {
	ID          uuid.UUID `json:"id"`
	Description string    `json:"desc"`
}

AddItem adds a todo item.

func (*AddItem) AggregateID

func (c *AddItem) AggregateID() uuid.UUID

func (*AddItem) AggregateType

func (c *AddItem) AggregateType() eh.AggregateType

func (*AddItem) CommandType

func (c *AddItem) CommandType() eh.CommandType

type Aggregate

type Aggregate struct {
	*events.AggregateBase
	// contains filtered or unexported fields
}

Aggregate is an aggregate for a todo list.

func (*Aggregate) ApplyEvent

func (a *Aggregate) ApplyEvent(ctx context.Context, event eh.Event) error

ApplyEvent implements the ApplyEvent method of the eventhorizon.Aggregate interface.

func (*Aggregate) HandleCommand

func (a *Aggregate) HandleCommand(ctx context.Context, cmd eh.Command) error

HandleCommand implements the HandleCommand method of the eventhorizon.CommandHandler interface.

type CheckAllItems

type CheckAllItems struct {
	ID      uuid.UUID `json:"id"`
	Checked bool      `json:"checked"`
}

CheckAllItems sets the checked status of all todo items.

func (*CheckAllItems) AggregateID

func (c *CheckAllItems) AggregateID() uuid.UUID

func (*CheckAllItems) AggregateType

func (c *CheckAllItems) AggregateType() eh.AggregateType

func (*CheckAllItems) CommandType

func (c *CheckAllItems) CommandType() eh.CommandType

type CheckItem

type CheckItem struct {
	ID      uuid.UUID `json:"id"`
	ItemID  int       `json:"item_id"`
	Checked bool      `json:"checked"`
}

CheckItem sets the checked status of a todo item.

func (*CheckItem) AggregateID

func (c *CheckItem) AggregateID() uuid.UUID

func (*CheckItem) AggregateType

func (c *CheckItem) AggregateType() eh.AggregateType

func (*CheckItem) CommandType

func (c *CheckItem) CommandType() eh.CommandType

type Create

type Create struct {
	ID uuid.UUID `json:"id"`
}

Create creates a new todo list.

func (*Create) AggregateID

func (c *Create) AggregateID() uuid.UUID

func (*Create) AggregateType

func (c *Create) AggregateType() eh.AggregateType

func (*Create) CommandType

func (c *Create) CommandType() eh.CommandType

type Delete

type Delete struct {
	ID uuid.UUID `json:"id"`
}

Delete deletes a todo list.

func (*Delete) AggregateID

func (c *Delete) AggregateID() uuid.UUID

func (*Delete) AggregateType

func (c *Delete) AggregateType() eh.AggregateType

func (*Delete) CommandType

func (c *Delete) CommandType() eh.CommandType

type HandlerAdder added in v0.15.0

type HandlerAdder interface {
	AddHandler(context.Context, eh.EventMatcher, eh.EventHandler) error
}

type ItemAddedData

type ItemAddedData struct {
	ItemID      int    `json:"item_id"     bson:"item_id"`
	Description string `json:"description" bson:"description"`
}

ItemAddedData is the event data for the ItemAdded event.

type ItemCheckedData

type ItemCheckedData struct {
	ItemID  int  `json:"item_id" bson:"item_id"`
	Checked bool `json:"checked" bson:"checked"`
}

ItemCheckedData is the event data for the ItemChecked event.

type ItemDescriptionSetData

type ItemDescriptionSetData struct {
	ItemID      int    `json:"item_id"     bson:"item_id"`
	Description string `json:"description" bson:"description"`
}

ItemDescriptionSetData is the event data for the ItemDescriptionSet event.

type ItemRemovedData

type ItemRemovedData struct {
	ItemID int `json:"item_id" bson:"item_id"`
}

ItemRemovedData is the event data for the ItemRemoved event.

type Projector

type Projector struct{}

Projector is a projector of todo list events on the TodoList read model.

func (*Projector) Project

func (p *Projector) Project(ctx context.Context,
	event eh.Event, entity eh.Entity) (eh.Entity, error)

Project implements the Project method of the eventhorizon.Projector interface.

func (*Projector) ProjectorType

func (p *Projector) ProjectorType() projector.Type

ProjectorType implements the ProjectorType method of the eventhorizon.Projector interface.

type RemoveCompletedItems

type RemoveCompletedItems struct {
	ID uuid.UUID `json:"id"`
}

RemoveCompletedItems removes all completed todo items.

func (*RemoveCompletedItems) AggregateID

func (c *RemoveCompletedItems) AggregateID() uuid.UUID

func (*RemoveCompletedItems) AggregateType

func (c *RemoveCompletedItems) AggregateType() eh.AggregateType

func (*RemoveCompletedItems) CommandType

func (c *RemoveCompletedItems) CommandType() eh.CommandType

type RemoveItem

type RemoveItem struct {
	ID     uuid.UUID `json:"id"`
	ItemID int       `json:"item_id"`
}

RemoveItem removes a todo item.

func (*RemoveItem) AggregateID

func (c *RemoveItem) AggregateID() uuid.UUID

func (*RemoveItem) AggregateType

func (c *RemoveItem) AggregateType() eh.AggregateType

func (*RemoveItem) CommandType

func (c *RemoveItem) CommandType() eh.CommandType

type SetItemDescription

type SetItemDescription struct {
	ID          uuid.UUID `json:"id"`
	ItemID      int       `json:"item_id"`
	Description string    `json:"desc"`
}

SetItemDescription sets the description of a todo item.

func (*SetItemDescription) AggregateID

func (c *SetItemDescription) AggregateID() uuid.UUID

func (*SetItemDescription) AggregateType

func (c *SetItemDescription) AggregateType() eh.AggregateType

func (*SetItemDescription) CommandType

func (c *SetItemDescription) CommandType() eh.CommandType

type TodoItem

type TodoItem struct {
	ID          int    `json:"id"        bson:"id"`
	Description string `json:"desc"      bson:"desc"`
	Completed   bool   `json:"completed" bson:"completed"`
}

TodoItem represents each item that can be completed in the todo list.

type TodoList

type TodoList struct {
	ID        uuid.UUID   `json:"id"         bson:"_id"`
	Version   int         `json:"version"    bson:"version"`
	Items     []*TodoItem `json:"items"      bson:"items"`
	CreatedAt time.Time   `json:"created_at" bson:"created_at"`
	UpdatedAt time.Time   `json:"updated_at" bson:"updated_at"`
}

TodoList is the read model for the todo list.

func (*TodoList) AggregateVersion

func (t *TodoList) AggregateVersion() int

AggregateVersion implements the AggregateVersion method of the eventhorizon.Versionable interface.

func (*TodoList) EntityID

func (t *TodoList) EntityID() uuid.UUID

EntityID implements the EntityID method of the eventhorizon.Entity interface.

Jump to

Keyboard shortcuts

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