diff --git a/lib/decentralised_book_index/metadata.ex b/lib/decentralised_book_index/metadata.ex index eb775ee..20931af 100644 --- a/lib/decentralised_book_index/metadata.ex +++ b/lib/decentralised_book_index/metadata.ex @@ -19,6 +19,10 @@ defmodule DecentralisedBookIndex.Metadata do args: [ :title, :description, + :language, + :format, + :page_count, + :published, :bids, :author_roles, :publisher_id, @@ -27,7 +31,7 @@ defmodule DecentralisedBookIndex.Metadata do define :add_book_to_related_editions_registry, action: :add_book_to_related_editions_registry, - args: [:title, :description, :bids, :author_roles, :publisher_id, :related_book_id] + args: [:title, :description, :language, :format, :page_count, :published, :bids, :author_roles, :publisher_id, :related_book_id] define :list_books, action: :read define :get_book_by_id, args: [:id], action: :by_id diff --git a/lib/decentralised_book_index/metadata/book.ex b/lib/decentralised_book_index/metadata/book.ex index d025fa9..e7b6f03 100644 --- a/lib/decentralised_book_index/metadata/book.ex +++ b/lib/decentralised_book_index/metadata/book.ex @@ -17,7 +17,7 @@ defmodule DecentralisedBookIndex.Metadata.Book do create :create do primary? true - accept [:title, :description, :publisher_id, :book_editions_registry_id] + accept [:title, :description, :format, :language, :page_count, :published, :publisher_id, :book_editions_registry_id] argument :bids, {:array, :map} argument :author_roles, {:array, :map} @@ -38,7 +38,7 @@ defmodule DecentralisedBookIndex.Metadata.Book do end create :add_book_to_related_editions_registry do - accept [:title, :description, :publisher_id] + accept [:title, :description, :format, :language, :page_count, :published, :publisher_id] argument :related_book_id, :uuid do allow_nil? false @@ -115,6 +115,26 @@ defmodule DecentralisedBookIndex.Metadata.Book do public? true end + attribute :published, :date do + allow_nil? false + public? true + end + + attribute :language, :string do + allow_nil? false + public? true + end + + attribute :format, :string do + allow_nil? false + public? true + end + + attribute :page_count, :integer do + allow_nil? false + public? true + end + timestamps() end diff --git a/priv/repo/migrations/20250315193949_update_book_to_add_published_language_format_and_page_count.exs b/priv/repo/migrations/20250315193949_update_book_to_add_published_language_format_and_page_count.exs new file mode 100644 index 0000000..663ee20 --- /dev/null +++ b/priv/repo/migrations/20250315193949_update_book_to_add_published_language_format_and_page_count.exs @@ -0,0 +1,27 @@ +defmodule DecentralisedBookIndex.Repo.Migrations.UpdateBookToAddPublishedLanguageFormatAndPageCount do + @moduledoc """ + Updates resources based on their most recent snapshots. + + This file was autogenerated with `mix ash_postgres.generate_migrations` + """ + + use Ecto.Migration + + def up do + alter table(:books) do + add :published, :date, null: false + add :language, :text, null: false + add :format, :text, null: false + add :page_count, :bigint, null: false + end + end + + def down do + alter table(:books) do + remove :page_count + remove :format + remove :language + remove :published + end + end +end diff --git a/priv/resource_snapshots/repo/books/20250315193950.json b/priv/resource_snapshots/repo/books/20250315193950.json new file mode 100644 index 0000000..e7f7a99 --- /dev/null +++ b/priv/resource_snapshots/repo/books/20250315193950.json @@ -0,0 +1,167 @@ +{ + "attributes": [ + { + "allow_nil?": false, + "default": "fragment(\"gen_random_uuid()\")", + "generated?": false, + "primary_key?": true, + "references": null, + "size": null, + "source": "id", + "type": "uuid" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "title", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "description", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "published", + "type": "date" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "language", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "format", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "page_count", + "type": "bigint" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "inserted_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "updated_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": { + "deferrable": false, + "destination_attribute": "id", + "destination_attribute_default": null, + "destination_attribute_generated": null, + "index?": false, + "match_type": null, + "match_with": null, + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "name": "books_book_editions_registry_id_fkey", + "on_delete": null, + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "book_editions_registries" + }, + "size": null, + "source": "book_editions_registry_id", + "type": "uuid" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": { + "deferrable": false, + "destination_attribute": "id", + "destination_attribute_default": null, + "destination_attribute_generated": null, + "index?": false, + "match_type": null, + "match_with": null, + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "name": "books_publisher_id_fkey", + "on_delete": null, + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "publishers" + }, + "size": null, + "source": "publisher_id", + "type": "uuid" + } + ], + "base_filter": null, + "check_constraints": [], + "custom_indexes": [], + "custom_statements": [], + "has_create_action": true, + "hash": "F7AD88CCF5ABCD96F14EB6E544A76677D1681A40ECE3491A2DCB1800DA38D5C4", + "identities": [], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.DecentralisedBookIndex.Repo", + "schema": null, + "table": "books" +} \ No newline at end of file diff --git a/test/decentralised_book_index/metadata/book_test.exs b/test/decentralised_book_index/metadata/book_test.exs index d53b661..a823260 100644 --- a/test/decentralised_book_index/metadata/book_test.exs +++ b/test/decentralised_book_index/metadata/book_test.exs @@ -9,7 +9,7 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do bids = bids() publisher = generate(publisher()) - assert {:ok, book} = Metadata.create_book("Book", "An description", bids, author_roles, publisher.id) + assert {:ok, book} = Metadata.create_book("Book", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id) assert book.book_editions_registry_id != nil end @@ -19,7 +19,7 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do publisher = generate(publisher()) assert {:ok, registry} = Metadata.create_book_editions_registry() - assert {:ok, book} = Metadata.create_book("Book", "An description", bids, author_roles, publisher.id, registry.id) + assert {:ok, book} = Metadata.create_book("Book", "An description","English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id, registry.id) assert book.book_editions_registry_id == registry.id end @@ -28,10 +28,10 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do bids = bids() publisher = generate(publisher()) - {:ok, related_book} = Metadata.create_book("Book", "An description", bids, author_roles, publisher.id) + {:ok, related_book} = Metadata.create_book("Book", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id) assert {:ok, book} = - Metadata.add_book_to_related_editions_registry("Book2", "An description2", bids, author_roles, publisher.id, related_book.id) + Metadata.add_book_to_related_editions_registry("Book2", "An description2", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id, related_book.id) assert related_book.book_editions_registry_id == book.book_editions_registry_id end @@ -42,7 +42,7 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do publisher = generate(publisher()) assert {:error, _} = - Metadata.add_book_to_related_editions_registry("Book2", "An description2", bids, author_roles, publisher.id, nil) + Metadata.add_book_to_related_editions_registry("Book2", "An description2", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id, nil) end end @@ -52,7 +52,7 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do bids = bids() publisher = generate(publisher()) - {:ok, book} = Metadata.create_book("Book", "An description", bids, author_roles, publisher.id) + {:ok, book} = Metadata.create_book("Book", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id) assert {:ok, alternatives_names} = Metadata.get_book_alternative_editions(book) assert alternatives_names = [] end @@ -62,10 +62,10 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do bids = bids() publisher = generate(publisher()) - {:ok, related_book} = Metadata.create_book("Book", "An description", bids, author_roles, publisher.id) + {:ok, related_book} = Metadata.create_book("Book", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id) {:ok, book} = - Metadata.add_book_to_related_editions_registry("Book2", "An description2", bids, author_roles, publisher.id, related_book.id) + Metadata.add_book_to_related_editions_registry("Book2", "An description2", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id, related_book.id) assert {:ok, alternatives_names} = Metadata.get_book_alternative_editions(book) assert alternatives_names = [related_book] @@ -82,7 +82,7 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do %{order: 1, author_id: author.id, role: ""} ] - {:ok, book} = Metadata.create_book("Book", "An description", bids, author_roles, publisher.id) + {:ok, book} = Metadata.create_book("Book", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id) assert {:ok, books} = Metadata.get_author_books(author) end @@ -100,7 +100,7 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do bids = bids() publisher = generate(publisher()) - {:ok, book} = Metadata.create_book("Book", "An description", bids, author_roles, publisher.id) + {:ok, book} = Metadata.create_book("Book", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id) author_roles = [ %{order: 1, author_id: alias1.id, role: ""} @@ -108,7 +108,7 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do bids2 = bids() publisher2 = generate(publisher()) - {:ok, book2} = Metadata.create_book("Book2", "An description", bids, author_roles, publisher2.id) + {:ok, book2} = Metadata.create_book("Book2", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher2.id) author_roles = [ %{order: 1, author_id: alias2.id, role: ""} @@ -116,7 +116,7 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do bids3 = bids() publisher3 = generate(publisher()) - {:ok, book3} = Metadata.create_book("Book3", "An description", bids, author_roles, publisher3.id) + {:ok, book3} = Metadata.create_book("Book3", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher3.id) assert {:ok, books} = Metadata.get_author_books(author) diff --git a/test/support/generators.ex b/test/support/generators.ex index e61d934..c1801b0 100644 --- a/test/support/generators.ex +++ b/test/support/generators.ex @@ -145,7 +145,11 @@ defmodule DecentralisedBookIndex.Generators do :create, defaults: [ title: sequence(:name, &"Book #{&1}"), - description: sequence(:name, &"Description #{&1}"), + description: sequence(:description, &"Description #{&1}"), + language: sequence(:language, &"Language #{&1}"), + format: sequence(:format, &"Format #{&1}"), + page_count: sequence(:page_count, & &1), + published: sequence(:published, &Date.add(~D[2025-03-04], &1)), bids: bids, author_roles: author_roles, publisher: publisher,