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
cba4de95
Commit
cba4de95
authored
Feb 08, 2021
by
Muhammad Rafif Elfazri
Browse files
Create Controller for Thread pagination
parent
13c589b9
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/diskuy_web/controllers/thread_pages_controller.ex
0 → 100644
View file @
cba4de95
defmodule
DiskuyWeb
.
ThreadPagesController
do
use
DiskuyWeb
,
:controller
alias
Diskuy
.
Forum
alias
Diskuy
.
ForumThreadPage
alias
Diskuy
.
Pagination
action_fallback
DiskuyWeb
.
FallbackController
# Pages Top Pattern Matching
def
pages_top
(
conn
,
%{
"after"
=>
cursor
})
do
page
=
ForumThreadPage
.
page_top
()
|>
Pagination
.
paginate_after
(
cursor
)
with
%{
entries:
entries
,
metadata:
metadata
}
=
page
do
render
(
conn
,
"pages.json"
,
%{
entries:
entries
,
metadata:
metadata
})
end
end
def
pages_top
(
conn
,
%{
"before"
=>
cursor
})
do
page
=
ForumThreadPage
.
page_top
()
|>
Pagination
.
paginate_before
(
cursor
)
with
%{
entries:
entries
,
metadata:
metadata
}
=
page
do
render
(
conn
,
"pages.json"
,
%{
entries:
entries
,
metadata:
metadata
})
end
end
def
pages_top
(
conn
,
_params
)
do
page
=
ForumThreadPage
.
page_top
()
|>
Pagination
.
paginate_start
with
%{
entries:
entries
,
metadata:
metadata
}
<-
page
do
render
(
conn
,
"pages.json"
,
%{
entries:
entries
,
metadata:
metadata
})
end
end
# Pages Recent Pattern Matching
def
pages_recent
(
conn
,
%{
"after"
=>
cursor
})
do
page
=
ForumThreadPage
.
page_recent
()
|>
Pagination
.
paginate_after
(
cursor
)
with
%{
entries:
entries
,
metadata:
metadata
}
=
page
do
render
(
conn
,
"pages.json"
,
%{
entries:
entries
,
metadata:
metadata
})
end
end
def
pages_recent
(
conn
,
%{
"before"
=>
cursor
})
do
page
=
ForumThreadPage
.
page_recent
()
|>
Pagination
.
paginate_before
(
cursor
)
with
%{
entries:
entries
,
metadata:
metadata
}
=
page
do
render
(
conn
,
"pages.json"
,
%{
entries:
entries
,
metadata:
metadata
})
end
end
def
pages_recent
(
conn
,
_params
)
do
page
=
ForumThreadPage
.
page_recent
()
|>
Pagination
.
paginate_start
with
%{
entries:
entries
,
metadata:
metadata
}
<-
page
do
render
(
conn
,
"pages.json"
,
%{
entries:
entries
,
metadata:
metadata
})
end
end
# Pages Search Pattern Matching
def
pages_search
(
conn
,
%{
"title"
=>
title
,
"after"
=>
cursor
})
do
page
=
ForumThreadPage
.
page_search
(
title
)
|>
Pagination
.
paginate_after
(
cursor
)
with
%{
entries:
entries
,
metadata:
metadata
}
=
page
do
render
(
conn
,
"pages.json"
,
%{
entries:
entries
,
metadata:
metadata
})
end
end
def
pages_search
(
conn
,
%{
"title"
=>
title
,
"before"
=>
cursor
})
do
page
=
ForumThreadPage
.
page_search
(
title
)
|>
Pagination
.
paginate_before
(
cursor
)
with
%{
entries:
entries
,
metadata:
metadata
}
=
page
do
render
(
conn
,
"pages.json"
,
%{
entries:
entries
,
metadata:
metadata
})
end
end
def
pages_search
(
conn
,
%{
"title"
=>
title
})
do
page
=
ForumThreadPage
.
page_search
(
title
)
|>
Pagination
.
paginate_start
with
%{
entries:
entries
,
metadata:
metadata
}
<-
page
do
render
(
conn
,
"pages.json"
,
%{
entries:
entries
,
metadata:
metadata
})
end
end
# Pages Per topic
def
pages_topic
(
conn
,
%{
"topic_id"
=>
topic_id
,
"after"
=>
cursor
})
do
page
=
ForumThreadPage
.
page_per_topic
(
topic_id
)
|>
Pagination
.
paginate_after
(
cursor
)
with
%{
entries:
entries
,
metadata:
metadata
}
=
page
do
render
(
conn
,
"pages.json"
,
%{
entries:
entries
,
metadata:
metadata
})
end
end
def
pages_topic
(
conn
,
%{
"topic_id"
=>
topic_id
,
"before"
=>
cursor
})
do
page
=
ForumThreadPage
.
page_per_topic
(
topic_id
)
|>
Pagination
.
paginate_before
(
cursor
)
with
%{
entries:
entries
,
metadata:
metadata
}
=
page
do
render
(
conn
,
"pages.json"
,
%{
entries:
entries
,
metadata:
metadata
})
end
end
def
pages_topic
(
conn
,
%{
"topic_id"
=>
topic_id
})
do
page
=
ForumThreadPage
.
page_per_topic
(
topic_id
)
|>
Pagination
.
paginate_start
with
%{
entries:
entries
,
metadata:
metadata
}
<-
page
do
render
(
conn
,
"pages.json"
,
%{
entries:
entries
,
metadata:
metadata
})
end
end
end
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