Skip to content

Commit

Permalink
fixup remove_node
Browse files Browse the repository at this point in the history
  • Loading branch information
electronicbites committed Aug 6, 2024
1 parent 87b0764 commit ad24583
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
5 changes: 1 addition & 4 deletions lib/radiator/outline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,7 @@ defmodule Radiator.Outline do
## Examples
iex> remove_node(node)
{:ok, %Node{}}
iex> remove_node(node)
{:error, %Ecto.Changeset{}}
{ %NodeRepoResult{} }
"""
def remove_node(%Node{} = node) do
Expand Down
21 changes: 15 additions & 6 deletions lib/radiator/outline/event_consumer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,23 @@ defmodule Radiator.Outline.EventConsumer do

defp process_command(%DeleteNodeCommand{node_id: node_id} = command) do
case NodeRepository.get_node(node_id) do
nil -> Logger.error("Could not remove node. Node not found.")
node -> Outline.remove_node(node)
nil ->
Logger.error("Could not remove node. Node not found.")

node ->
result = Outline.remove_node(node)

%NodeDeletedEvent{
node_id: node_id,
uuid: command.event_id,
user_id: command.user_id,
children: result.children,
next_id: result.next_id
}
|> EventStore.persist_event()
|> Dispatch.broadcast()
end

%NodeDeletedEvent{node_id: node_id, uuid: command.event_id, user_id: command.user_id}
|> EventStore.persist_event()
|> Dispatch.broadcast()

:ok
end

Expand Down

0 comments on commit ad24583

Please sign in to comment.