Add the Publisher resource.
This commit is contained in:
@@ -88,5 +88,13 @@ defmodule DecentralisedBookIndex.Metadata do
|
||||
define :update_book_id, action: :update
|
||||
define :destroy_book_id, action: :destroy
|
||||
end
|
||||
|
||||
resource DecentralisedBookIndex.Metadata.Publisher do
|
||||
define :create_publisher, action: :create, args: [:name]
|
||||
define :list_publishers, action: :read
|
||||
define :get_publisher_by_id, args: [:id], action: :by_id
|
||||
define :update_publisher, action: :update
|
||||
define :destroy_publisher, action: :destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,7 +17,7 @@ defmodule DecentralisedBookIndex.Metadata.Book do
|
||||
|
||||
create :create do
|
||||
primary? true
|
||||
accept [:title, :description, :book_editions_registry_id]
|
||||
accept [:title, :description, :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]
|
||||
accept [:title, :description, :publisher_id]
|
||||
|
||||
argument :related_book_id, :uuid do
|
||||
allow_nil? false
|
||||
@@ -121,6 +121,8 @@ defmodule DecentralisedBookIndex.Metadata.Book do
|
||||
relationships do
|
||||
belongs_to :book_editions_registry, Metadata.BookEditionsRegistry
|
||||
|
||||
belongs_to :publisher, Metadata.Publisher
|
||||
|
||||
has_many :author_roles, Metadata.AuthorRole do
|
||||
sort order: :asc
|
||||
public? true
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
defmodule DecentralisedBookIndex.Metadata.Publisher do
|
||||
use Ash.Resource,
|
||||
otp_app: :decentralised_book_index,
|
||||
domain: DecentralisedBookIndex.Metadata,
|
||||
data_layer: AshPostgres.DataLayer
|
||||
|
||||
require Ash.Query
|
||||
alias DecentralisedBookIndex.Metadata
|
||||
|
||||
postgres do
|
||||
table "publishers"
|
||||
repo DecentralisedBookIndex.Repo
|
||||
end
|
||||
|
||||
actions do
|
||||
defaults [:read, :update, :destroy]
|
||||
|
||||
create :create do
|
||||
primary? true
|
||||
accept [:name]
|
||||
end
|
||||
|
||||
read :by_id do
|
||||
argument :id, :uuid, allow_nil?: false
|
||||
get? true
|
||||
filter expr(id == ^arg(:id))
|
||||
end
|
||||
end
|
||||
|
||||
attributes do
|
||||
uuid_primary_key :id
|
||||
|
||||
attribute :name, :string do
|
||||
allow_nil? false
|
||||
public? true
|
||||
end
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
relationships do
|
||||
has_many :books, Metadata.Book
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user