Skip to content

Commit

Permalink
rename prev_node_id, parent_node_id => prev_id, parent_id
Browse files Browse the repository at this point in the history
  • Loading branch information
electronicbites committed Sep 6, 2024
1 parent 78f21a2 commit b2952b5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
20 changes: 10 additions & 10 deletions lib/radiator/outline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ defmodule Radiator.Outline do
# if no previous node is given, the new node will be inserted as the first child of the parent node
def insert_node(attrs) do
Repo.transaction(fn ->
prev_node_id = attrs["prev_id"]
parent_node_id = attrs["parent_id"]
prev_id = attrs["prev_id"]
parent_id = attrs["parent_id"]
episode_id = attrs["episode_id"]
# find Node which has been previously connected to prev_node
next_node =
Node
|> where(episode_id: ^episode_id)
|> where_prev_node_equals(prev_node_id)
|> where_parent_node_equals(parent_node_id)
|> where_prev_node_equals(prev_id)
|> where_parent_node_equals(parent_id)
|> Repo.one()

with prev_node <- NodeRepository.get_node_if(prev_node_id),
parent_node <- find_parent_node(prev_node, parent_node_id),
with prev_node <- NodeRepository.get_node_if(prev_id),
parent_node <- find_parent_node(prev_node, parent_id),
true <- parent_and_prev_consistent?(parent_node, prev_node),
true <- episode_valid?(episode_id, parent_node, prev_node),
{:ok, node} <- NodeRepository.create_node(set_parent_id_if(attrs, parent_node)),
{:ok, _node_to_move} <- move_node_if(next_node, parent_node_id, node.uuid) do
{:ok, _node_to_move} <- move_node_if(next_node, parent_id, node.uuid) do
%NodeRepoResult{node: node, next_id: get_node_id(next_node)}
else
false ->
Expand Down Expand Up @@ -455,11 +455,11 @@ defmodule Radiator.Outline do

defp move_node_if(nil, _parent_node_id, _prev_node_id), do: {:ok, nil}

defp move_node_if(node, parent_node_id, prev_node_id) do
defp move_node_if(node, parent_id, prev_id) do
node
|> Node.move_node_changeset(%{
parent_id: parent_node_id,
prev_id: prev_node_id
parent_id: parent_id,
prev_id: prev_id
})
|> Repo.update()
end
Expand Down
6 changes: 3 additions & 3 deletions lib/radiator/outline/command.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ defmodule Radiator.Outline.Command do
}
end

def build("move_node", node_id, parent_node_id, prev_node_id, user_id, event_id) do
def build("move_node", node_id, parent_id, prev_id, user_id, event_id) do
%MoveNodeCommand{
event_id: event_id,
user_id: user_id,
node_id: node_id,
parent_id: parent_node_id,
prev_id: prev_node_id
parent_id: parent_id,
prev_id: prev_id
}
end
end
6 changes: 3 additions & 3 deletions lib/radiator/outline/dispatch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ defmodule Radiator.Outline.Dispatch do
end

def move_node(node_id, user_id, event_id,
parent_node_id: parent_node_id,
prev_node_id: prev_node_id
parent_id: parent_id,
prev_id: prev_id
) do
"move_node"
|> Command.build(node_id, parent_node_id, prev_node_id, user_id, event_id)
|> Command.build(node_id, parent_id, prev_id, user_id, event_id)
|> EventProducer.enqueue()
end

Expand Down
4 changes: 2 additions & 2 deletions lib/radiator_web/live/outline_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ defmodule RadiatorWeb.OutlineComponent do
}

user_id = socket.assigns.user_id
Dispatch.move_node(uuid, user_id, generate_event_id(socket.id), prev_node_id: prev_id)
Dispatch.move_node(uuid, user_id, generate_event_id(socket.id), prev_id: prev_id)

socket
|> stream_insert(:nodes, to_change_form(node, %{}))
Expand All @@ -232,7 +232,7 @@ defmodule RadiatorWeb.OutlineComponent do
}

user_id = socket.assigns.user_id
Dispatch.move_node(uuid, user_id, generate_event_id(socket.id), parent_node_id: parent_id)
Dispatch.move_node(uuid, user_id, generate_event_id(socket.id), parent_id: parent_id)

socket
|> stream_insert(:nodes, to_change_form(node, %{}))
Expand Down

0 comments on commit b2952b5

Please sign in to comment.