From 4b29f4dd0102af2f41eb4dd4cc67feefb5b4d00a Mon Sep 17 00:00:00 2001 From: Luka Dornhecker Date: Sun, 19 May 2024 20:52:55 +0200 Subject: [PATCH] allow empty nodes --- lib/radiator/outline.ex | 7 +++++-- lib/radiator/outline/event_consumer.ex | 3 +++ lib/radiator/outline/node.ex | 3 +-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/radiator/outline.ex b/lib/radiator/outline.ex index 39a17c4e..aa7449ed 100644 --- a/lib/radiator/outline.ex +++ b/lib/radiator/outline.ex @@ -9,6 +9,8 @@ defmodule Radiator.Outline do alias Radiator.Outline.NodeRepository alias Radiator.Repo + require Logger + @doc """ Inserts a node. @@ -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 diff --git a/lib/radiator/outline/event_consumer.ex b/lib/radiator/outline/event_consumer.ex index 332cbc52..f7fa2e82 100644 --- a/lib/radiator/outline/event_consumer.ex +++ b/lib/radiator/outline/event_consumer.ex @@ -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) @@ -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} diff --git a/lib/radiator/outline/node.ex b/lib/radiator/outline/node.ex index a5125fdc..a11b50ef 100644 --- a/lib/radiator/outline/node.ex +++ b/lib/radiator/outline/node.ex @@ -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 @@ -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