Add an action to get author's alternatives names.

This commit is contained in:
2025-03-08 21:28:46 +02:00
parent f0f7037447
commit ee72055f81
3 changed files with 34 additions and 1 deletions
+1
View File
@@ -10,6 +10,7 @@ defmodule DecentralisedBookIndex.Metadata do
define :add_author_to_related_alias_registry, action: :add_author_to_related_alias_registry, args: [:name, :description, :related_author_id]
define :list_authors, action: :read
define :get_author_by_id, args: [:id], action: :by_id
define :get_author_alternative_names, args: [:author], action: :get_alternative_names
define :update_author, action: :update
define :destroy_author, action: :destroy
end
@@ -4,6 +4,8 @@ defmodule DecentralisedBookIndex.Metadata.Author do
domain: DecentralisedBookIndex.Metadata,
data_layer: AshPostgres.DataLayer
require Ash.Query
postgres do
table "authors"
repo DecentralisedBookIndex.Repo
@@ -54,6 +56,18 @@ defmodule DecentralisedBookIndex.Metadata.Author do
get? true
filter expr(id == ^arg(:id))
end
read :get_alternative_names do
argument :author, :struct, allow_nil?: false
prepare fn query, context ->
author = query.arguments.author
DecentralisedBookIndex.Metadata.Author
|> Ash.Query.filter(author_alias_registry_id == ^author.author_alias_registry_id
and id != ^author.id)
end
end
end
attributes do