Update the create action for Author to set AuthorAliasRegistry.
This commit is contained in:
@@ -6,7 +6,7 @@ defmodule DecentralisedBookIndex.Metadata do
|
||||
resource DecentralisedBookIndex.Metadata.Book
|
||||
|
||||
resource DecentralisedBookIndex.Metadata.Author do
|
||||
define :create_author, action: :create, args: [:name, :description, :author_alias_registry_id]
|
||||
define :create_author, action: :create, args: [:name, :description, {:optional, :author_alias_registry_id}]
|
||||
define :add_author_to_alias_registry, action: :add_author_to_alias_registry, args: [:author_alias_registry_id]
|
||||
define :list_authors, action: :read
|
||||
define :get_author_by_id, args: [:id], action: :by_id
|
||||
|
||||
@@ -20,6 +20,25 @@ defmodule DecentralisedBookIndex.Metadata.Author do
|
||||
primary? true
|
||||
accept [:name, :description, :author_alias_registry_id]
|
||||
|
||||
change fn changeset, _ ->
|
||||
registry_id = Ash.Changeset.get_attribute(changeset, :author_alias_registry_id)
|
||||
|
||||
if registry_id == nil do
|
||||
{:ok, registry} = DecentralisedBookIndex.Metadata.create_author_alias_registry()
|
||||
|
||||
Ash.Changeset.force_change_attribute(changeset, :author_alias_registry_id, registry.id)
|
||||
else
|
||||
changeset
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
read :by_id do
|
||||
argument :id, :uuid, allow_nil?: false
|
||||
get? true
|
||||
filter expr(id == ^arg(:id))
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user