|
|
@ -12,10 +12,6 @@ defmodule DecentralisedBookIndex.Metadata.Author do
|
|
|
|
actions do
|
|
|
|
actions do
|
|
|
|
defaults [:read, :update, :destroy]
|
|
|
|
defaults [:read, :update, :destroy]
|
|
|
|
|
|
|
|
|
|
|
|
update :add_author_to_alias_registry do
|
|
|
|
|
|
|
|
accept [:author_alias_registry_id]
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
create :create do
|
|
|
|
create :create do
|
|
|
|
primary? true
|
|
|
|
primary? true
|
|
|
|
accept [:name, :description, :author_alias_registry_id]
|
|
|
|
accept [:name, :description, :author_alias_registry_id]
|
|
|
@ -33,13 +29,31 @@ defmodule DecentralisedBookIndex.Metadata.Author do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
create :add_author_to_related_alias_registry do
|
|
|
|
|
|
|
|
accept [:name, :description]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
argument :related_author_id, :uuid do
|
|
|
|
|
|
|
|
allow_nil? false
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
change fn changeset, context ->
|
|
|
|
|
|
|
|
related_author_id = changeset.arguments.related_author_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if related_author_id == nil do
|
|
|
|
|
|
|
|
Ash.Changeset.add_error(changeset, :related_author_id, "Related author is empty")
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{:ok, related_author} = DecentralisedBookIndex.Metadata.get_author_by_id(related_author_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ash.Changeset.force_change_attribute(changeset, :author_alias_registry_id, related_author.author_alias_registry_id)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
read :by_id do
|
|
|
|
read :by_id do
|
|
|
|
argument :id, :uuid, allow_nil?: false
|
|
|
|
argument :id, :uuid, allow_nil?: false
|
|
|
|
get? true
|
|
|
|
get? true
|
|
|
|
filter expr(id == ^arg(:id))
|
|
|
|
filter expr(id == ^arg(:id))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
attributes do
|
|
|
|
attributes do
|
|
|
|