Add the action to get author's ids.

This commit is contained in:
2025-03-13 18:54:42 +02:00
parent c546c61268
commit d6eef962de
3 changed files with 40 additions and 0 deletions
+1
View File
@@ -38,6 +38,7 @@ defmodule DecentralisedBookIndex.Metadata do
define :list_authors, action: :read
define :get_author_by_id, args: [:id], action: :by_id
define :get_author_ids, args: [:author], action: :get_author_ids
define :get_author_alternative_names, args: [:author], action: :get_alternative_names
define :search_author, action: :search, args: [:name]
define :update_author, action: :update
@@ -82,6 +82,22 @@ defmodule DecentralisedBookIndex.Metadata.Author do
end
end
action :get_author_ids, :vector do
argument :author, :struct, allow_nil?: false
run fn input, _ ->
author = input.arguments.author
{:ok, ids} =
DecentralisedBookIndex.Metadata.Author
|> Ash.Query.filter(author_alias_registry_id == ^author.author_alias_registry_id)
|> Ash.Query.select([:id])
|> Ash.read()
{:ok, Enum.map(ids, & &1.id)}
end
end
read :search do
argument :name, :ci_string do
constraints allow_empty?: true