index.community/backend/lib/backend_web/views/search_view.ex

31 lines
657 B
Elixir
Raw Permalink Normal View History

defmodule BackendWeb.SearchView do
use BackendWeb, :view
alias BackendWeb.SearchView
2019-07-23 14:08:43 +00:00
import Backend.Util
2019-07-26 22:30:11 +00:00
def render("index.json", %{hits: hits, next: next}) do
%{
2019-07-26 22:30:11 +00:00
results: render_many(hits, SearchView, "instance.json", as: :hit),
next: next
}
end
2019-07-26 22:30:11 +00:00
def render("instance.json", %{hit: hit}) do
2019-07-23 14:08:43 +00:00
threshold = get_config(:personal_instance_threshold)
description =
2019-07-26 22:30:11 +00:00
if hit.user_count != nil and hit.user_count < threshold do
2019-07-23 14:08:43 +00:00
nil
else
2019-07-26 22:30:11 +00:00
hit.description
2019-07-23 14:08:43 +00:00
end
%{
2019-07-26 22:30:11 +00:00
name: hit.domain,
2019-07-23 14:08:43 +00:00
description: description,
2019-07-26 22:30:11 +00:00
userCount: hit.user_count,
type: hit.type
}
end
end