mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-01 03:46:44 +01:00
return page struct
This commit is contained in:
parent
c28c3b914a
commit
df6532a7af
1 changed files with 11 additions and 2 deletions
|
@ -16,7 +16,7 @@ defmodule PhilomenaWeb.TopicController do
|
||||||
|> Repo.one()
|
|> Repo.one()
|
||||||
|
|
||||||
conn = conn |> assign(:topic, topic)
|
conn = conn |> assign(:topic, topic)
|
||||||
%{page_number: page, page_size: page_size} = conn.assigns.pagination
|
%{page_number: page} = conn.assigns.pagination
|
||||||
|
|
||||||
posts =
|
posts =
|
||||||
Post
|
Post
|
||||||
|
@ -24,7 +24,16 @@ defmodule PhilomenaWeb.TopicController do
|
||||||
|> where([p], p.topic_position >= ^(25 * (page - 1)) and p.topic_position < ^(25 * page))
|
|> where([p], p.topic_position >= ^(25 * (page - 1)) and p.topic_position < ^(25 * page))
|
||||||
|> order_by(asc: :created_at)
|
|> order_by(asc: :created_at)
|
||||||
|> preload([:user, topic: :forum])
|
|> 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)
|
render(conn, "show.html", posts: posts)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue