podbox_ash/lib/podbox/podcast/resources/enclosure.ex

60 lines
1.3 KiB
Elixir

defmodule Podbox.Podcast.Enclosure do
@moduledoc """
A podcast enclosure.
"""
alias Podbox.{
Download.Asset,
Podcast,
Podcast.AssetEnclosure,
Podcast.CreateEnclosureChange,
Podcast.Episode,
Repo
}
use Ash.Resource,
data_layer: AshSqlite.DataLayer,
domain: Podcast,
notifiers: [Ash.Notifier.PubSub]
@type t :: Ash.Resource.record()
attributes do
uuid_primary_key :id
attribute :url, :string, allow_nil?: false, public?: true
attribute :length, :integer, allow_nil?: false, public?: true, constraints: [min: 0]
attribute :mime_type, :string, allow_nil?: false, public?: true
create_timestamp :inserted_at
update_timestamp :updated_at
end
relationships do
belongs_to :episode, Episode, attribute_writable?: true, public?: true
many_to_many :assets, Asset, through: AssetEnclosure, public?: true
has_many :asset_enclosures, AssetEnclosure, public?: false
end
actions do
defaults [:read, :destroy, update: :*]
create :create do
accept [:url, :length, :mime_type]
primary? true
change CreateEnclosureChange
end
end
sqlite do
repo Repo
table "podcast_enclosures"
end
pub_sub do
module Podbox.PubSub
prefix "podcast:enclosure"
publish :create, "created"
end
end