Fakultas Ilmu Komputer UI

Commit 72191581 authored by Muhammad Rafif Elfazri's avatar Muhammad Rafif Elfazri
Browse files

Add pagination for threads made by user

parent 821f7ba6
......@@ -31,6 +31,12 @@ defmodule Diskuy.ForumThreadPage do
|> order_by([tr], desc: tr.inserted_at, asc: tr.title)
end
def page_per_user(username) do
query_start()
|> where([tr, to, u], u.username == ^username)
|> order_by([tr], desc: tr.inserted_at, asc: tr.title)
end
defp query_start do
Thread
|> join(:inner, [tr], to in Topic, as: :topics, on: tr.topic_id == to.id)
......
......@@ -33,6 +33,12 @@ defmodule DiskuyWeb.ThreadPagesController do
paginate_and_render(conn, query)
end
# Pages Per User
def pages_user(conn, %{"username" => username}) do
query = ForumThreadPage.page_per_user(username)
paginate_and_render(conn, query)
end
defp paginate_and_render(conn, query) do
case conn.params do
......
......@@ -61,6 +61,9 @@ defmodule DiskuyWeb.Router do
options "/threads/pages/search/:title", ThreadPagesController, :options
get "/threads/pages/topic/:topic_id", ThreadPagesController, :pages_topic
options "/threads/pages/topic/:topic_id", ThreadPagesController, :options
get "/threads/pages/user/:username", ThreadPagesController, :pages_user
options "/threads/pages/user/:username", ThreadPagesController, :options
resources "/threads", ThreadController, except: [:new, :edit, :create, :update, :delete]
options "/threads", ThreadController, :options
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment