Skip to content

Commit

Permalink
allow empty nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukad committed May 19, 2024
1 parent d47c503 commit 4b29f4d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/radiator/outline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ defmodule Radiator.Outline do
alias Radiator.Outline.NodeRepository
alias Radiator.Repo

require Logger

@doc """
Inserts a node.
Expand Down Expand Up @@ -50,8 +52,9 @@ defmodule Radiator.Outline do
false ->
Repo.rollback("Insert node failed. Parent and prev node are not consistent.")

{:error, _} ->
Repo.rollback("Insert node failed. Unkown error")
{:error, error} ->
Logger.error("Insert node failed. #{inspect(error)}")
Repo.rollback("Insert node failed. Unknown error")
end
end)
end
Expand Down
3 changes: 3 additions & 0 deletions lib/radiator/outline/event_consumer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ defmodule Radiator.Outline.EventConsumer do
alias Radiator.Outline.Dispatch
alias Radiator.Outline.Event.{NodeContentChangedEvent, NodeInsertedEvent}

require Logger

def start_link(opts \\ []) do
{name, opts} = Keyword.pop(opts, :name, __MODULE__)
GenStage.start_link(__MODULE__, opts, name: name)
Expand All @@ -19,6 +21,7 @@ defmodule Radiator.Outline.EventConsumer do
end

def handle_events([command], _from, state) do
Logger.debug("Processing command: #{inspect(command)}")
process_command(command)

{:noreply, [], state}
Expand Down
3 changes: 1 addition & 2 deletions lib/radiator/outline/node.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ defmodule Radiator.Outline.Node do
|> cast(attributes, [:uuid, :content, :episode_id, :creator_id, :parent_id, :prev_id])
|> put_uuid()
|> update_change(:content, &trim/1)
|> validate_required([:content, :episode_id])
|> validate_required([:episode_id])
|> validate_format(:uuid, ~r/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i)
|> unique_constraint(:uuid, name: "outline_nodes_pkey")
end
Expand All @@ -46,7 +46,6 @@ defmodule Radiator.Outline.Node do
node
|> cast(attrs, [:content])
|> update_change(:content, &trim/1)
|> validate_required([:content])
end

def move_node_changeset(node, attrs) do
Expand Down

0 comments on commit 4b29f4d

Please sign in to comment.