Add the action to get Book by a BookId.
continuous-integration/drone/push Build is passing Details

dev
KKlochko 4 months ago
parent 23cfb1009a
commit 5f064a3235

@ -30,6 +30,7 @@ defmodule DecentralisedBookIndex.Metadata do
define :list_books, action: :read
define :get_book_by_id, args: [:id], action: :by_id
define :get_book_by_bid, args: [:type, :bid], action: :by_bid
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

@ -69,6 +69,13 @@ defmodule DecentralisedBookIndex.Metadata.Book do
filter expr(id == ^arg(:id))
end
read :by_bid do
argument :type, :string, allow_nil?: false
argument :bid, :string, allow_nil?: false
get? true
filter expr(exists(bids, type == ^arg(:type) and bid == ^arg(:bid)))
end
read :get_alternative_editions do
argument :book, :struct, allow_nil?: false

@ -117,4 +117,26 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
assert book3.id in book_ids
end
end
describe "get a book by book id" do
test "get by bid" do
{:ok, author} = Metadata.create_author("Author", "An description")
type = "isbn10"
bid = "1234567890"
bids = [
%{order: 1, type: type, bid: bid}
]
author_roles = [
%{order: 1, author_id: author.id, role: ""}
]
{:ok, expected_book} = Metadata.create_book("Book", "An description", bids, author_roles)
assert {:ok, book} = Metadata.get_book_by_bid(type, bid)
assert expected_book.id == book.id
end
end
end

Loading…
Cancel
Save