Add the brief_description for Book and Author.

This commit is contained in:
2025-04-28 12:08:00 +03:00
parent 6021d3e8c8
commit af11f13942
6 changed files with 67 additions and 0 deletions
@@ -9,6 +9,9 @@ defmodule DecentralisedBookIndex.Metadata.Author do
require Ash.Query
alias DecentralisedBookIndex.Metadata
@brief_description_length 20
@brief_description_max_length @brief_description_length + 3
json_api do
type "author"
end
@@ -241,4 +244,16 @@ defmodule DecentralisedBookIndex.Metadata.Author do
has_many :author_role, Metadata.AuthorRole
end
calculations do
calculate :brief_description,
:string,
expr(
if(string_length(description) <= @brief_description_max_length) do
description
else
fragment("substr(?, 1, ?)", description, @brief_description_length) <> "..."
end
)
end
end
@@ -9,6 +9,9 @@ defmodule DecentralisedBookIndex.Metadata.Book do
require Ash.Query
alias DecentralisedBookIndex.Metadata
@brief_description_length 20
@brief_description_max_length @brief_description_length + 3
json_api do
type "book"
end
@@ -366,4 +369,16 @@ defmodule DecentralisedBookIndex.Metadata.Book do
public? true
end
end
calculations do
calculate :brief_description,
:string,
expr(
if(string_length(description) <= @brief_description_max_length) do
description
else
fragment("substr(?, 1, ?)", description, @brief_description_length) <> "..."
end
)
end
end
@@ -63,6 +63,7 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Index do
page =
Metadata.search_author!(
search_query,
load: [:brief_description],
query: [sort_input: sort_by],
page: page_params ++ [count: true],
actor: socket.assigns.current_user
@@ -189,6 +189,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.Index do
"title" ->
Metadata.search_book!(
search_query,
load: [:brief_description],
query: [sort_input: sort_by],
page: page_params ++ [count: true],
actor: actor
@@ -198,6 +199,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.Index do
Metadata.search_book_by_bid!(
type,
search_query,
load: [:brief_description],
query: [sort_input: sort_by],
page: page_params ++ [count: true],
actor: actor