This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user