This commit is contained in:
@@ -61,7 +61,13 @@ defmodule DecentralisedBookIndex.Metadata do
|
||||
define :destroy_book_editions_registry, action: :destroy
|
||||
end
|
||||
|
||||
resource DecentralisedBookIndex.Metadata.AuthorRole
|
||||
resource DecentralisedBookIndex.Metadata.AuthorRole do
|
||||
define :create_author_role, action: :create, args: [:author_id, :order, :role]
|
||||
define :list_author_roles, action: :read
|
||||
define :get_author_role_by_id, args: [:id], action: :by_id
|
||||
define :update_author_role, action: :update
|
||||
define :destroy_author_role, action: :destroy
|
||||
end
|
||||
end
|
||||
|
||||
json_api do
|
||||
|
||||
@@ -18,6 +18,24 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRole do
|
||||
primary? true
|
||||
accept [:order, :role]
|
||||
argument :author_id, :uuid
|
||||
|
||||
change fn changeset, _ ->
|
||||
author_id = changeset.arguments.author_id
|
||||
|
||||
if author_id != nil do
|
||||
{:ok, author} = DecentralisedBookIndex.Metadata.get_author_by_id(author_id)
|
||||
|
||||
Ash.Changeset.force_change_attribute(changeset, :author_id, author.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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user