Add the action to get author's books.
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-03-13 17:41:14 +02:00
parent 70542781c2
commit c546c61268
3 changed files with 26 additions and 0 deletions
+1
View File
@@ -22,6 +22,7 @@ defmodule DecentralisedBookIndex.Metadata do
define :list_books, action: :read
define :get_book_by_id, args: [:id], action: :by_id
define :get_book_alternative_editions, args: [:book], action: :get_alternative_editions
define :get_author_books, args: [:author], action: :get_author_books
define :update_book, action: :update
define :destroy_book, action: :destroy
end
@@ -76,6 +76,17 @@ defmodule DecentralisedBookIndex.Metadata.Book do
and id != ^book.id)
end
end
read :get_author_books do
argument :author, :struct, allow_nil?: false
prepare fn query, context ->
author = query.arguments.author
Metadata.Book
|> Ash.Query.filter(expr(exists(author_roles, author_id == ^author.id)))
end
end
end
attributes do