Skip to content

Commit

Permalink
add episode reference id to nodes
Browse files Browse the repository at this point in the history
currently it is optional but it should be required
  • Loading branch information
electronicbites committed Dec 21, 2023
1 parent a0ede33 commit ecf667f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/radiator/outline/node.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Radiator.Outline.Node do
"""
use Ecto.Schema
import Ecto.Changeset
alias Radiator.Podcast.Episode

@derive {Jason.Encoder, only: [:uuid, :content, :creator_id, :parent_id, :prev_id]}

Expand All @@ -15,6 +16,8 @@ defmodule Radiator.Outline.Node do
field :parent_id, Ecto.UUID
field :prev_id, Ecto.UUID

belongs_to :episode, Episode

timestamps(type: :utc_datetime)
end

Expand All @@ -25,7 +28,8 @@ defmodule Radiator.Outline.Node do
@optional_fields [
:creator_id,
:parent_id,
:prev_id
:prev_id,
:episode_id # FIXME: should be required
]

@all_fields @optional_fields ++ @required_fields
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Radiator.Repo.Migrations.AddOutlineReferenceToEpisode do
use Ecto.Migration

def change do
alter table(:outline_nodes) do
add :episode_id, references(:episodes, on_delete: :nothing)
end
end
end
10 changes: 7 additions & 3 deletions test/support/fixtures/outline_fixtures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ defmodule Radiator.OutlineFixtures do
This module defines test helpers for creating
entities via the `Radiator.Outline` context.
"""

alias Radiator.PodcastFixtures
@doc """
Generate a node.
"""
def node_fixture(attrs \\ %{}) do
episode = PodcastFixtures.episode_fixture()

{:ok, node} =
attrs
|> Enum.into(%{content: "some content"})
|> Enum.into(%{
content: "some content",
episode_id: episode.id
})
|> Radiator.Outline.create_node()

node
end
end

0 comments on commit ecf667f

Please sign in to comment.