2 Commits
Author SHA1 Message Date
KKlochko ddcab0b843 Update the API get actions to use the by_id action.
continuous-integration/drone/push Build is passing
2025-05-21 19:42:13 +03:00
KKlochko b7979bf6ba Add descriptions for resources' actions. 2025-05-21 19:41:28 +03:00
7 changed files with 67 additions and 7 deletions
+4 -4
View File
@@ -6,7 +6,7 @@ defmodule DecentralisedBookIndex.Metadata do
json_api do json_api do
routes do routes do
base_route "/books", Metadata.Book do base_route "/books", Metadata.Book do
get :read get :by_id
index :search index :search
related :bids, :read, primary?: true related :bids, :read, primary?: true
@@ -15,17 +15,17 @@ defmodule DecentralisedBookIndex.Metadata do
end end
base_route "/authors", Metadata.Author do base_route "/authors", Metadata.Author do
get :read get :by_id
index :search index :search
end end
base_route "/publishers", Metadata.Publisher do base_route "/publishers", Metadata.Publisher do
get :read get :by_id
index :search index :search
end end
base_route "/servers", Metadata.DBIServer do base_route "/servers", Metadata.DBIServer do
get :read get :by_id
index :search index :search
end end
end end
@@ -25,6 +25,10 @@ defmodule DecentralisedBookIndex.Metadata.Author do
end end
end end
resource do
description "An author's metadata."
end
actions do actions do
defaults [:read, :destroy] defaults [:read, :destroy]
@@ -100,6 +104,7 @@ defmodule DecentralisedBookIndex.Metadata.Author do
end end
read :by_id do read :by_id do
description "Return the Author by its id."
argument :id, :uuid, allow_nil?: false argument :id, :uuid, allow_nil?: false
get? true get? true
filter expr(id == ^arg(:id)) filter expr(id == ^arg(:id))
@@ -136,7 +141,10 @@ defmodule DecentralisedBookIndex.Metadata.Author do
end end
read :search do read :search do
description "Return a list of Authors, optionally filtering by name."
argument :name, :ci_string do argument :name, :ci_string do
description "Return Authors, which names includes the name."
constraints allow_empty?: true constraints allow_empty?: true
default "" default ""
end end
@@ -21,8 +21,12 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRole do
end end
end end
resource do
description "A metadata of an author's role."
end
actions do actions do
defaults [:read, :destroy] defaults [:destroy]
create :create do create :create do
primary? true primary? true
@@ -43,13 +47,20 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRole do
end end
end end
read :read do
description "Return a list of AuthorRoles."
primary? true
end
read :by_id do read :by_id do
description "Return the AuthorRole by its id."
argument :id, :uuid, allow_nil?: false argument :id, :uuid, allow_nil?: false
get? true get? true
filter expr(id == ^arg(:id)) filter expr(id == ^arg(:id))
end end
read :by_book_id do read :by_book_id do
description "Return the AuthorRole by its BookId."
argument :book_id, :uuid, allow_nil?: false argument :book_id, :uuid, allow_nil?: false
filter expr(book_id == ^arg(:book_id)) filter expr(book_id == ^arg(:book_id))
end end
@@ -25,6 +25,10 @@ defmodule DecentralisedBookIndex.Metadata.Book do
end end
end end
resource do
description "A book's metadata."
end
actions do actions do
defaults [:read, :destroy] defaults [:read, :destroy]
@@ -142,6 +146,7 @@ defmodule DecentralisedBookIndex.Metadata.Book do
end end
read :by_id do read :by_id do
description "Return the Book by its id."
argument :id, :uuid, allow_nil?: false argument :id, :uuid, allow_nil?: false
get? true get? true
filter expr(id == ^arg(:id)) filter expr(id == ^arg(:id))
@@ -182,7 +187,10 @@ defmodule DecentralisedBookIndex.Metadata.Book do
end end
read :search do read :search do
description "Return a list of Books, optionally filtering by title."
argument :query, :ci_string do argument :query, :ci_string do
description "Return Books, which titles includes the query."
constraints allow_empty?: true constraints allow_empty?: true
default "" default ""
end end
@@ -193,6 +201,8 @@ defmodule DecentralisedBookIndex.Metadata.Book do
end end
read :search_by_bid do read :search_by_bid do
description "Return a list of Books, optionally filtering by BookId."
argument :type, :string, allow_nil?: false argument :type, :string, allow_nil?: false
argument :bid, :string, allow_nil?: false argument :bid, :string, allow_nil?: false
@@ -26,8 +26,12 @@ defmodule DecentralisedBookIndex.Metadata.BookId do
end end
end end
resource do
description "A book's identifier."
end
actions do actions do
defaults [:read, :destroy] defaults [:destroy]
create :create do create :create do
primary? true primary? true
@@ -39,7 +43,13 @@ defmodule DecentralisedBookIndex.Metadata.BookId do
accept [:id, :type, :bid, :order] accept [:id, :type, :bid, :order]
end end
read :read do
description "Return a list of BookIds."
primary? true
end
read :by_id do read :by_id do
description "Return the BookId by its id."
argument :id, :uuid, allow_nil?: false argument :id, :uuid, allow_nil?: false
get? true get? true
filter expr(id == ^arg(:id)) filter expr(id == ^arg(:id))
@@ -21,6 +21,10 @@ defmodule DecentralisedBookIndex.Metadata.DBIServer do
end end
end end
resource do
description "An DBIServer's metadata."
end
actions do actions do
defaults [:read, :destroy] defaults [:read, :destroy]
@@ -43,13 +47,17 @@ defmodule DecentralisedBookIndex.Metadata.DBIServer do
end end
read :by_id do read :by_id do
description "Return the DBIServer by its id."
argument :id, :uuid, allow_nil?: false argument :id, :uuid, allow_nil?: false
get? true get? true
filter expr(id == ^arg(:id)) filter expr(id == ^arg(:id))
end end
read :search do read :search do
description "Return a list of DBIServers, optionally filtering by name."
argument :name, :ci_string do argument :name, :ci_string do
description "Return DBIServers, which names includes the name."
constraints allow_empty?: true constraints allow_empty?: true
default "" default ""
end end
@@ -22,8 +22,12 @@ defmodule DecentralisedBookIndex.Metadata.Publisher do
end end
end end
resource do
description "An publisher's metadata."
end
actions do actions do
defaults [:read, :destroy] defaults [:destroy]
create :create do create :create do
primary? true primary? true
@@ -34,14 +38,23 @@ defmodule DecentralisedBookIndex.Metadata.Publisher do
accept [:id, :name, :inserted_at, :updated_at, :dbi_server_id] accept [:id, :name, :inserted_at, :updated_at, :dbi_server_id]
end end
read :read do
description "Return a list of Publishers."
primary? true
end
read :by_id do read :by_id do
description "Return the Publisher by its id."
argument :id, :uuid, allow_nil?: false argument :id, :uuid, allow_nil?: false
get? true get? true
filter expr(id == ^arg(:id)) filter expr(id == ^arg(:id))
end end
read :search do read :search do
description "Return a list of Publishers, optionally filtering by name."
argument :name, :ci_string do argument :name, :ci_string do
description "Return Publishers, which names includes the name."
constraints allow_empty?: true constraints allow_empty?: true
default "" default ""
end end