Update the Book to add language, format, page_count, published date.
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
+27
@@ -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
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user