Fakultas Ilmu Komputer UI

post_pages_controller.ex 647 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
defmodule DiskuyWeb.PostPagesController do
  use DiskuyWeb, :controller
  alias Diskuy.ForumPostPage
  alias Diskuy.Repo


  # Pages Per threads
  def pages_thread(conn, %{"thread_id" => thread_id, "page" => page_num}) do
    page = ForumPostPage.page_per_thread(thread_id) |> Repo.paginate(page: page_num)
    with %{entries: _entries} <- page do
      render(conn, "pages.json", %{page: page})
    end
  end

  def pages_thread(conn, %{"thread_id" => thread_id}) do
    page = ForumPostPage.page_per_thread(thread_id) |> Repo.paginate()
    with %{entries: _entries} <- page do
      render(conn, "pages.json", %{page: page})
    end
  end

end