File tree Expand file tree Collapse file tree 4 files changed +24
-0
lines changed Expand file tree Collapse file tree 4 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ defmodule TodoBackend.Router do
33
44 alias TodoBackend.Todos.Aggregates.Todo
55 alias TodoBackend.Todos.Commands.CreateTodo
6+ alias TodoBackend.Todos.Commands.DeleteTodo
67
78 dispatch ( [ CreateTodo ] , to: Todo , identity: :uuid )
9+ dispatch ( [ DeleteTodo ] , to: Todo , identity: :uuid )
810end
Original file line number Diff line number Diff line change @@ -9,8 +9,10 @@ defmodule TodoBackend.Todos.Aggregates.Todo do
99 alias TodoBackend.Todos.Aggregates.Todo
1010
1111 alias TodoBackend.Todos.Commands.CreateTodo
12+ alias TodoBackend.Todos.Commands.DeleteTodo
1213
1314 alias TodoBackend.Todos.Events.TodoCreated
15+ alias TodoBackend.Todos.Events.TodoDeleted
1416
1517 def execute ( % Todo { uuid: nil } , % CreateTodo { } = create ) do
1618 % TodoCreated {
@@ -21,6 +23,10 @@ defmodule TodoBackend.Todos.Aggregates.Todo do
2123 }
2224 end
2325
26+ def execute ( % Todo { uuid: uuid } , % DeleteTodo { uuid: uuid } ) do
27+ % TodoDeleted { uuid: uuid }
28+ end
29+
2430 def apply ( % Todo { } = todo , % TodoCreated { } = created ) do
2531 % Todo {
2632 todo
@@ -30,3 +36,8 @@ defmodule TodoBackend.Todos.Aggregates.Todo do
3036 order: created . order
3137 }
3238 end
39+
40+ def apply ( % Todo { uuid: uuid } , % TodoDeleted { uuid: uuid } ) do
41+ nil
42+ end
43+ end
Original file line number Diff line number Diff line change 1+ defmodule TodoBackend.Todos.Commands.DeleteTodo do
2+ defstruct [
3+ :uuid
4+ ]
5+ end
Original file line number Diff line number Diff line change 1+ defmodule TodoBackend.Todos.Events.TodoDeleted do
2+ @ derive Jason.Encoder
3+ defstruct [
4+ :uuid
5+ ]
6+ end
You can’t perform that action at this time.
0 commit comments