return page struct

This commit is contained in:
byte[] 2019-10-08 19:40:26 -04:00
parent c28c3b914a
commit df6532a7af

View file

@ -16,7 +16,7 @@ defmodule PhilomenaWeb.TopicController do
|> Repo.one()
conn = conn |> assign(:topic, topic)
%{page_number: page, page_size: page_size} = conn.assigns.pagination
%{page_number: page} = conn.assigns.pagination
posts =
Post
@ -24,7 +24,16 @@ defmodule PhilomenaWeb.TopicController do
|> where([p], p.topic_position >= ^(25 * (page - 1)) and p.topic_position < ^(25 * page))
|> order_by(asc: :created_at)
|> preload([:user, topic: :forum])
|> Repo.paginate(conn.assigns.scrivener)
|> Repo.all()
posts =
%Scrivener.Page{
entries: posts,
page_number: page,
page_size: 25,
total_entries: topic.post_count,
total_pages: div(topic.post_count + 25 - 1, 25)
}
render(conn, "show.html", posts: posts)
end