Skip to content

Commit 488627b

Browse files
implement todo deletion command
1 parent dc6e9fb commit 488627b

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

lib/todo_backend/router.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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)
810
end

lib/todo_backend/todos/aggregates/todo.ex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
defmodule TodoBackend.Todos.Commands.DeleteTodo do
2+
defstruct [
3+
:uuid
4+
]
5+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
defmodule TodoBackend.Todos.Events.TodoDeleted do
2+
@derive Jason.Encoder
3+
defstruct [
4+
:uuid
5+
]
6+
end

0 commit comments

Comments
 (0)