Update Book resource and its tests.
This commit is contained in:
@@ -39,11 +39,13 @@ defmodule DecentralisedBookIndex.Metadata.Book do
|
||||
argument :bids, {:array, :map}
|
||||
argument :author_roles, {:array, :map}
|
||||
|
||||
change fn changeset, _ ->
|
||||
change fn changeset, context ->
|
||||
actor = Map.get(context, :actor, nil)
|
||||
|
||||
registry_id = Ash.Changeset.get_attribute(changeset, :book_editions_registry_id)
|
||||
|
||||
if registry_id == nil do
|
||||
{:ok, registry} = DecentralisedBookIndex.Metadata.create_book_editions_registry()
|
||||
registry = DecentralisedBookIndex.Metadata.create_book_editions_registry!(actor: actor)
|
||||
|
||||
Ash.Changeset.force_change_attribute(changeset, :book_editions_registry_id, registry.id)
|
||||
else
|
||||
@@ -75,11 +77,12 @@ defmodule DecentralisedBookIndex.Metadata.Book do
|
||||
argument :bids, {:array, :map}
|
||||
argument :author_roles, {:array, :map}
|
||||
|
||||
change fn changeset, _ ->
|
||||
change fn changeset, context ->
|
||||
actor = Map.get(context, :actor, nil)
|
||||
registry_id = Ash.Changeset.get_attribute(changeset, :book_editions_registry_id)
|
||||
|
||||
if registry_id == nil do
|
||||
{:ok, registry} = DecentralisedBookIndex.Metadata.create_book_editions_registry()
|
||||
registry = DecentralisedBookIndex.Metadata.create_book_editions_registry!(actor: actor)
|
||||
|
||||
Ash.Changeset.force_change_attribute(changeset, :book_editions_registry_id, registry.id)
|
||||
else
|
||||
@@ -332,16 +335,12 @@ defmodule DecentralisedBookIndex.Metadata.Book do
|
||||
public? true
|
||||
end
|
||||
|
||||
timestamps() do
|
||||
timestamps do
|
||||
writable? true
|
||||
public? true
|
||||
end
|
||||
end
|
||||
|
||||
validations do
|
||||
validate numericality(:page_count, greater_than: 0)
|
||||
end
|
||||
|
||||
relationships do
|
||||
belongs_to :dbi_server, Metadata.DBIServer
|
||||
|
||||
|
||||
Reference in New Issue
Block a user