Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/radiator/podcasts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ defmodule Radiator.Podcasts do
define :update_episode, action: :update
define :add_persona, action: :add_persona
define :remove_persona, action: :remove_persona
define :begin_scheduling, action: :begin_scheduling
define :finalize_scheduling, action: :finalize_scheduling
define :back_to_scheduling, action: :back_to_scheduling
end

resource Radiator.Podcasts.Chapter
Expand All @@ -35,13 +38,26 @@ defmodule Radiator.Podcasts do
resource Radiator.Podcasts.Track

resource Radiator.Podcasts.Person do
define :read_persons, action: :read
define :create_person, action: :create
end

resource Radiator.Podcasts.Persona do
define :read_personas, action: :read
define :create_persona, action: :create
end

resource Radiator.Podcasts.Episode.Scheduling do
define :start_scheduling, action: :create
define :get_by_episode, action: :by_episode
define :add_proposal, action: :add_proposal
define :remove_proposal, action: :remove_proposal
define :vote, action: :vote
define :remove_vote, action: :remove_vote
define :finalize, action: :finalize
define :reopen, action: :reopen
end

resource Radiator.Podcasts.EpisodePersona
resource Radiator.Podcasts.Role
end
Expand Down
32 changes: 31 additions & 1 deletion lib/radiator/podcasts/episode.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
defmodule Radiator.Podcasts.Episode do
@moduledoc false
@moduledoc """
Model specification for podcast episodes. Ash state machine is used to define the
different states of an episode.
"""

use Ash.Resource,
otp_app: :radiator,
Expand All @@ -19,6 +22,12 @@ defmodule Radiator.Podcasts.Episode do
state_machine do
initial_states([:scheduling])
default_initial_state(:scheduling)

transitions do
transition(:begin_scheduling, from: :creation, to: :scheduling)
transition(:finalize_scheduling, from: :scheduling, to: :scheduled)
transition(:back_to_scheduling, from: :scheduled, to: :scheduling)
end
end

@default_accept_attributes [
Expand Down Expand Up @@ -55,6 +64,22 @@ defmodule Radiator.Podcasts.Episode do
argument :personas, {:array, :uuid}, allow_nil?: true
change manage_relationship(:personas, type: :remove, value_is_key: :id)
end

update :begin_scheduling do
description "Transition episode to scheduling state"
change transition_state(:scheduling)
end

update :finalize_scheduling do
description "Transition episode to scheduled state after scheduling is complete"
accept [:publication_date]
change transition_state(:scheduled)
end

update :back_to_scheduling do
description "Reopen scheduling for an episode"
change transition_state(:scheduling)
end
end

attributes do
Expand Down Expand Up @@ -129,6 +154,11 @@ defmodule Radiator.Podcasts.Episode do
end

has_many :tracks, Radiator.Podcasts.Track

has_one :scheduling, Radiator.Podcasts.Episode.Scheduling do
description "The scheduling information for this episode"
public? true
end
end

identities do
Expand Down
Loading
Loading