philomena/lib/philomena_web/controllers/comment_controller.ex

35 lines
825 B
Elixir
Raw Normal View History

2019-11-12 04:10:41 +01:00
defmodule PhilomenaWeb.CommentController do
use PhilomenaWeb, :controller
2019-11-13 04:12:46 +01:00
alias Philomena.{Comments.Comment, Textile.Renderer}
2019-11-12 04:10:41 +01:00
import Ecto.Query
def index(conn, _params) do
comments =
Comment.search_records(
%{
query: %{
bool: %{
must: [
%{range: %{posted_at: %{gt: "now-1w"}}},
%{term: %{hidden_from_users: false}}
]
}
},
sort: %{posted_at: :desc}
},
conn.assigns.pagination,
Comment |> preload([:image, user: [awards: :badge]])
)
rendered =
comments.entries
|> Renderer.render_collection()
comments =
%{comments | entries: Enum.zip(comments.entries, rendered)}
render(conn, "index.html", comments: comments)
end
end