smokestack/test/support/post.ex

53 lines
929 B
Elixir
Raw Normal View History

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
belongs_to :author, Support.Author
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
calculations do
calculate :full_title, :string, concat([:title, :sub_title], ": ")
end
2023-08-10 21:01:45 +12:00
end