Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Functional Programming
Diskuy-Backend
Commits
72191581
Commit
72191581
authored
Feb 15, 2021
by
Muhammad Rafif Elfazri
Browse files
Add pagination for threads made by user
parent
821f7ba6
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/diskuy/forum_thread_page.ex
View file @
72191581
...
...
@@ -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
)
...
...
lib/diskuy_web/controllers/thread_pages_controller.ex
View file @
72191581
...
...
@@ -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
...
...
lib/diskuy_web/router.ex
View file @
72191581
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment