Skip to content

Commit

Permalink
fixup: pass episode id to function. could end up in ambiguous results
Browse files Browse the repository at this point in the history
  • Loading branch information
electronicbites committed Nov 29, 2024
1 parent 06b9233 commit 40a908f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/radiator/outline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,10 @@ defmodule Radiator.Outline do

Repo.transaction(fn ->
old_next_node =
NodeRepository.get_node_by_parent_and_prev(get_node_id(parent_node), node.uuid)
NodeRepository.get_node_by_parent_and_prev(get_node_id(parent_node), node.uuid, node.episode_id)

new_next_node =
NodeRepository.get_node_by_parent_and_prev(new_parent_id, new_prev_id)
NodeRepository.get_node_by_parent_and_prev(new_parent_id, new_prev_id, node.episode_id)

{:ok, node} = NodeRepository.move_node_if(node, new_parent_id, new_prev_id)

Expand Down
11 changes: 7 additions & 4 deletions lib/radiator/outline/node_repository.ex
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,20 @@ defmodule Radiator.Outline.NodeRepository do
end

@doc """
Gets a single node defined by the given prev_id and parent_id.
Gets a single node defined by the given prev_id and parent_id and the
episode id.
Returns `nil` if the Node cannot be found.
## Examples
iex> get_node_by_parent_and_prev("5adf3b360fb0", "380d56cf")
iex> get_node_by_parent_and_prev("5adf3b360fb0", "380d56cf", 23)
nil
iex> get_node_by_parent_and_prev("5e3f5a0422a4", "b78a976d")
iex> get_node_by_parent_and_prev("5e3f5a0422a4", "b78a976d", 23)
%Node{uuid: "33b2a1dac9b1", parent_id: "5e3f5a0422a4", prev_id: "b78a976d"}
"""
def get_node_by_parent_and_prev(parent_id, prev_id) do
def get_node_by_parent_and_prev(parent_id, prev_id, episode_id) do
Node
|> where(episode_id: ^episode_id)
|> where_prev_node_equals(prev_id)
|> where_parent_node_equals(parent_id)
|> Repo.one()
Expand Down

0 comments on commit 40a908f

Please sign in to comment.