Incident.Aggregate behaviour (incident v0.6.1) View Source

An aggregate is the unit of business logic in the domain. The business logic is used to handle commands and also to apply events to change the aggregate state.

This behaviour defines the callbacks for command execution and event application.

Link to this section Summary

Callbacks

Receives a persisted event and the aggregate state, performing an aggregate state update.

Receives and executes the command, performing a specific business logic for it, usually considering the aggregate state as part of the logic.

Link to this section Callbacks

Specs

apply(struct(), map()) :: map()

Receives a persisted event and the aggregate state, performing an aggregate state update.

Specs

execute(struct()) :: {:ok, struct(), map()} | {:error, atom()}

Receives and executes the command, performing a specific business logic for it, usually considering the aggregate state as part of the logic.

In case of a successful command and logic, a new event is composed and returned along with the aggregate state.

In case of an unsuccessful command and logic, an error is returned containing a business logic reason.