You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.4 KiB
74 lines
1.4 KiB
defmodule DecentralisedBookIndex.Metadata.Publisher do
|
|
use Ash.Resource,
|
|
otp_app: :decentralised_book_index,
|
|
domain: DecentralisedBookIndex.Metadata,
|
|
data_layer: AshPostgres.DataLayer,
|
|
extensions: [AshJsonApi.Resource]
|
|
|
|
require Ash.Query
|
|
alias DecentralisedBookIndex.Metadata
|
|
|
|
json_api do
|
|
type "publisher"
|
|
end
|
|
|
|
postgres do
|
|
table "publishers"
|
|
repo DecentralisedBookIndex.Repo
|
|
end
|
|
|
|
actions do
|
|
defaults [:read, :update, :destroy]
|
|
|
|
create :create do
|
|
primary? true
|
|
accept [:name]
|
|
end
|
|
|
|
create :sync_create do
|
|
accept [:id, :name, :inserted_at, :updated_at, :dbi_server_id]
|
|
end
|
|
|
|
read :by_id do
|
|
argument :id, :uuid, allow_nil?: false
|
|
get? true
|
|
filter expr(id == ^arg(:id))
|
|
end
|
|
|
|
read :search do
|
|
argument :name, :ci_string do
|
|
constraints allow_empty?: true
|
|
default ""
|
|
end
|
|
|
|
filter expr(contains(name, ^arg(:name)))
|
|
|
|
pagination offset?: true, default_limit: 10
|
|
end
|
|
|
|
update :sync do
|
|
accept [:name, :inserted_at, :updated_at, :dbi_server_id]
|
|
end
|
|
end
|
|
|
|
attributes do
|
|
uuid_primary_key :id, writable?: true
|
|
|
|
attribute :name, :string do
|
|
allow_nil? false
|
|
public? true
|
|
end
|
|
|
|
timestamps() do
|
|
writable? true
|
|
public? true
|
|
end
|
|
end
|
|
|
|
relationships do
|
|
belongs_to :dbi_server, Metadata.DBIServer
|
|
|
|
has_many :books, Metadata.Book
|
|
end
|
|
end
|