|
|
@ -13,7 +13,7 @@ defmodule DecentralisedBookIndex.Metadata.Book do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
actions do
|
|
|
|
actions do
|
|
|
|
defaults [:read, :update, :destroy]
|
|
|
|
defaults [:read, :destroy]
|
|
|
|
|
|
|
|
|
|
|
|
create :create do
|
|
|
|
create :create do
|
|
|
|
primary? true
|
|
|
|
primary? true
|
|
|
@ -112,6 +112,29 @@ defmodule DecentralisedBookIndex.Metadata.Book do
|
|
|
|
pagination offset?: true, default_limit: 10
|
|
|
|
pagination offset?: true, default_limit: 10
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
|
|
|
argument :bids, {:array, :map}
|
|
|
|
|
|
|
|
argument :author_roles, {:array, :map}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
change fn changeset, _ ->
|
|
|
|
|
|
|
|
registry_id = Ash.Changeset.get_attribute(changeset, :book_editions_registry_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if registry_id == nil do
|
|
|
|
|
|
|
|
{:ok, registry} = DecentralisedBookIndex.Metadata.create_book_editions_registry()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ash.Changeset.force_change_attribute(changeset, :book_editions_registry_id, registry.id)
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
changeset
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
change manage_relationship(:bids, type: :direct_control, order_is_key: :order)
|
|
|
|
|
|
|
|
change manage_relationship(:author_roles, type: :direct_control, order_is_key: :order)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
update :assign_cover_image do
|
|
|
|
update :assign_cover_image do
|
|
|
|
accept [:cover_image_url]
|
|
|
|
accept [:cover_image_url]
|
|
|
|
end
|
|
|
|
end
|
|
|
|