2023-08-10 21:01:45 +12:00
|
|
|
defmodule Support.Post do
|
|
|
|
@moduledoc false
|
|
|
|
|
|
|
|
use Ash.Resource,
|
|
|
|
data_layer: Ash.DataLayer.Ets,
|
2024-03-28 10:04:54 +13:00
|
|
|
validate_domain_inclusion?: false,
|
|
|
|
domain: nil
|
2023-08-10 21:01:45 +12:00
|
|
|
|
|
|
|
ets do
|
|
|
|
private? true
|
|
|
|
end
|
|
|
|
|
|
|
|
attributes do
|
|
|
|
uuid_primary_key :id
|
|
|
|
|
|
|
|
attribute :title, :string do
|
|
|
|
allow_nil? false
|
2024-03-28 10:04:54 +13:00
|
|
|
public? true
|
2023-08-10 21:01:45 +12:00
|
|
|
end
|
|
|
|
|
2024-03-28 10:04:54 +13:00
|
|
|
attribute :sub_title, :string, public?: true
|
2023-08-10 21:01:45 +12:00
|
|
|
|
|
|
|
attribute :tags, {:array, :ci_string} do
|
|
|
|
constraints items: [
|
|
|
|
match: ~r/^[a-zA-Z]+$/,
|
|
|
|
casing: :lower
|
|
|
|
]
|
2024-03-28 10:04:54 +13:00
|
|
|
|
|
|
|
public? true
|
2023-08-10 21:01:45 +12:00
|
|
|
end
|
|
|
|
|
|
|
|
attribute :body, :string do
|
|
|
|
allow_nil? false
|
2024-03-28 10:04:54 +13:00
|
|
|
public? true
|
2023-08-10 21:01:45 +12:00
|
|
|
end
|
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
relationships do
|
2024-05-20 16:57:18 +12:00
|
|
|
belongs_to :author, Support.Author, attribute_writable?: true
|
2023-08-10 21:01:45 +12:00
|
|
|
end
|
|
|
|
|
|
|
|
actions do
|
|
|
|
defaults [:create, :read, :update, :destroy]
|
2024-03-28 10:04:54 +13:00
|
|
|
default_accept :*
|
2023-08-10 21:01:45 +12:00
|
|
|
end
|
2023-09-05 19:37:00 +12:00
|
|
|
|
|
|
|
calculations do
|
|
|
|
calculate :full_title, :string, concat([:title, :sub_title], ": ")
|
|
|
|
end
|
2023-08-10 21:01:45 +12:00
|
|
|
end
|