51 lines
1.1 KiB
Elixir
51 lines
1.1 KiB
Elixir
|
defmodule Podbox.Podcast.Image do
|
||
|
@moduledoc """
|
||
|
A podcast image.
|
||
|
"""
|
||
|
|
||
|
alias Podbox.{Podcast, Podcast.Show, 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 :title, :string, allow_nil?: true, public?: true
|
||
|
attribute :link, :string, allow_nil?: true, public?: true
|
||
|
attribute :width, :integer, allow_nil?: true, public?: true, constraints: [min: 1]
|
||
|
attribute :height, :integer, allow_nil?: true, public?: true, constraints: [min: 1]
|
||
|
|
||
|
create_timestamp :inserted_at
|
||
|
update_timestamp :updated_at
|
||
|
end
|
||
|
|
||
|
actions do
|
||
|
defaults [:read, :destroy, create: :*, update: :*]
|
||
|
end
|
||
|
|
||
|
relationships do
|
||
|
belongs_to :show, Show, attribute_writable?: true, public?: true
|
||
|
end
|
||
|
|
||
|
sqlite do
|
||
|
repo Repo
|
||
|
table "podcast_images"
|
||
|
end
|
||
|
|
||
|
pub_sub do
|
||
|
module Podbox.PubSub
|
||
|
prefix "podcast:image"
|
||
|
publish :create, "created"
|
||
|
end
|
||
|
|
||
|
identities do
|
||
|
identity :unique_by_show, [:show_id]
|
||
|
end
|
||
|
end
|