|
|
|
@ -2,11 +2,16 @@ defmodule DecentralisedBookIndex.Metadata.Book do
|
|
|
|
|
use Ash.Resource,
|
|
|
|
|
otp_app: :decentralised_book_index,
|
|
|
|
|
domain: DecentralisedBookIndex.Metadata,
|
|
|
|
|
data_layer: AshPostgres.DataLayer
|
|
|
|
|
data_layer: AshPostgres.DataLayer,
|
|
|
|
|
extensions: [AshJsonApi.Resource]
|
|
|
|
|
|
|
|
|
|
require Ash.Query
|
|
|
|
|
alias DecentralisedBookIndex.Metadata
|
|
|
|
|
|
|
|
|
|
json_api do
|
|
|
|
|
type "book"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
postgres do
|
|
|
|
|
table "books"
|
|
|
|
|
repo DecentralisedBookIndex.Repo
|
|
|
|
@ -17,7 +22,19 @@ defmodule DecentralisedBookIndex.Metadata.Book do
|
|
|
|
|
|
|
|
|
|
create :create do
|
|
|
|
|
primary? true
|
|
|
|
|
accept [:title, :description, :format, :language, :page_count, :published, :publisher_id, :cover_image_url, :book_editions_registry_id]
|
|
|
|
|
|
|
|
|
|
accept [
|
|
|
|
|
:title,
|
|
|
|
|
:description,
|
|
|
|
|
:format,
|
|
|
|
|
:language,
|
|
|
|
|
:page_count,
|
|
|
|
|
:published,
|
|
|
|
|
:publisher_id,
|
|
|
|
|
:cover_image_url,
|
|
|
|
|
:book_editions_registry_id
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
argument :bids, {:array, :map}
|
|
|
|
|
argument :author_roles, {:array, :map}
|
|
|
|
|
|
|
|
|
@ -38,7 +55,16 @@ defmodule DecentralisedBookIndex.Metadata.Book do
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
create :add_book_to_related_editions_registry do
|
|
|
|
|
accept [:title, :description, :format, :language, :page_count, :published, :publisher_id, :cover_image_url]
|
|
|
|
|
accept [
|
|
|
|
|
:title,
|
|
|
|
|
:description,
|
|
|
|
|
:format,
|
|
|
|
|
:language,
|
|
|
|
|
:page_count,
|
|
|
|
|
:published,
|
|
|
|
|
:publisher_id,
|
|
|
|
|
:cover_image_url
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
argument :related_book_id, :uuid do
|
|
|
|
|
allow_nil? false
|
|
|
|
@ -55,7 +81,11 @@ defmodule DecentralisedBookIndex.Metadata.Book do
|
|
|
|
|
else
|
|
|
|
|
{:ok, related_book} = DecentralisedBookIndex.Metadata.get_book_by_id(related_book_id)
|
|
|
|
|
|
|
|
|
|
Ash.Changeset.force_change_attribute(changeset, :book_editions_registry_id, related_book.book_editions_registry_id)
|
|
|
|
|
Ash.Changeset.force_change_attribute(
|
|
|
|
|
changeset,
|
|
|
|
|
:book_editions_registry_id,
|
|
|
|
|
related_book.book_editions_registry_id
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -83,8 +113,10 @@ defmodule DecentralisedBookIndex.Metadata.Book do
|
|
|
|
|
book = query.arguments.book
|
|
|
|
|
|
|
|
|
|
DecentralisedBookIndex.Metadata.Book
|
|
|
|
|
|> Ash.Query.filter(book_editions_registry_id == ^book.book_editions_registry_id
|
|
|
|
|
and id != ^book.id)
|
|
|
|
|
|> Ash.Query.filter(
|
|
|
|
|
book_editions_registry_id == ^book.book_editions_registry_id and
|
|
|
|
|
id != ^book.id
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -115,7 +147,19 @@ defmodule DecentralisedBookIndex.Metadata.Book do
|
|
|
|
|
update :update do
|
|
|
|
|
primary? true
|
|
|
|
|
require_atomic? false
|
|
|
|
|
accept [:title, :description, :format, :language, :page_count, :published, :publisher_id, :cover_image_url, :book_editions_registry_id]
|
|
|
|
|
|
|
|
|
|
accept [
|
|
|
|
|
:title,
|
|
|
|
|
:description,
|
|
|
|
|
:format,
|
|
|
|
|
:language,
|
|
|
|
|
:page_count,
|
|
|
|
|
:published,
|
|
|
|
|
:publisher_id,
|
|
|
|
|
:cover_image_url,
|
|
|
|
|
:book_editions_registry_id
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
argument :bids, {:array, :map}
|
|
|
|
|
argument :author_roles, {:array, :map}
|
|
|
|
|
|
|
|
|
|