Add the update action for the Book FormComponent.

This commit is contained in:
2025-04-01 14:38:52 +03:00
parent 72875c20d2
commit 5f786cfb4b
3 changed files with 53 additions and 4 deletions
@@ -47,12 +47,12 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRole do
update :update do
primary? true
accept [:order, :role]
argument :author_id, :uuid
argument :author_id, :uuid, allow_nil?: true
require_atomic? false
change fn changeset, _ ->
author_id = changeset.arguments.author_id
author_id =
Map.get(changeset.arguments, :author_id, nil)
if author_id != nil do
{:ok, author} = DecentralisedBookIndex.Metadata.get_author_by_id(author_id)
+24 -1
View File
@@ -13,7 +13,7 @@ defmodule DecentralisedBookIndex.Metadata.Book do
end
actions do
defaults [:read, :update, :destroy]
defaults [:read, :destroy]
create :create do
primary? true
@@ -112,6 +112,29 @@ defmodule DecentralisedBookIndex.Metadata.Book do
pagination offset?: true, default_limit: 10
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
accept [:cover_image_url]
end