File tree Expand file tree Collapse file tree 5 files changed +59
-0
lines changed Expand file tree Collapse file tree 5 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 11defmodule TodoBackend.App do
22 use Commanded.Application , otp_app: :todo_backend
3+
4+ router ( TodoBackend.Router )
35end
Original file line number Diff line number Diff line change 1+ defmodule TodoBackend.Router do
2+ use Commanded.Commands.Router
3+
4+ alias TodoBackend.Todos.Aggregates.Todo
5+ alias TodoBackend.Todos.Commands.CreateTodo
6+
7+ dispatch ( [ CreateTodo ] , to: Todo , identity: :uuid )
8+ end
Original file line number Diff line number Diff line change 1+ defmodule TodoBackend.Todos.Aggregates.Todo do
2+ defstruct [
3+ :uuid ,
4+ :title ,
5+ :completed ,
6+ :order
7+ ]
8+
9+ alias TodoBackend.Todos.Aggregates.Todo
10+
11+ alias TodoBackend.Todos.Commands.CreateTodo
12+
13+ alias TodoBackend.Todos.Events.TodoCreated
14+
15+ def execute ( % Todo { uuid: nil } , % CreateTodo { } = create ) do
16+ % TodoCreated {
17+ uuid: create . uuid ,
18+ title: create . title ,
19+ completed: create . completed ,
20+ order: create . order
21+ }
22+ end
23+
24+ def apply ( % Todo { } = todo , % TodoCreated { } = created ) do
25+ % Todo {
26+ todo
27+ | uuid: created . uuid ,
28+ title: created . title ,
29+ completed: created . completed ,
30+ order: created . order
31+ }
32+ end
Original file line number Diff line number Diff line change 1+ defmodule TodoBackend.Todos.Commands.CreateTodo do
2+ defstruct [
3+ :uuid ,
4+ :title ,
5+ :completed ,
6+ :order
7+ ]
8+ end
Original file line number Diff line number Diff line change 1+ defmodule TodoBackend.Todos.Events.TodoCreated do
2+ @ derive Jason.Encoder
3+ defstruct [
4+ :uuid ,
5+ :title ,
6+ :completed ,
7+ :order
8+ ]
9+ end
You can’t perform that action at this time.
0 commit comments