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
462ccd21
Commit
462ccd21
authored
Feb 08, 2021
by
Muhammad Rafif Elfazri
Browse files
Create Query Builder module for Post Schema
parent
752a9d80
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/diskuy/forum_post_page.ex
0 → 100644
View file @
462ccd21
defmodule
Diskuy
.
ForumPostPage
do
@moduledoc
"""
The Query Builder For Paging Thread Schema.
"""
import
Ecto
.
Query
,
warn:
false
alias
Diskuy
.
Account
.
User
alias
Diskuy
.
Forum
.
Thread
alias
Diskuy
.
Forum
.
Post
def
page_per_thread
(
thread_id
)
do
query_start
()
|>
where
([
p
],
p
.
thread_id
==
^
thread_id
)
|>
order_by
([
p
],
asc:
p
.
inserted_at
)
end
defp
query_start
do
Post
|>
join
(
:inner
,
[
p
],
u
in
User
,
as:
:users
,
on:
p
.
user_id
==
u
.
id
)
|>
join
(
:left
,
[
p
],
tr
in
Thread
,
as:
:threads
,
on:
p
.
thread_id
==
tr
.
id
)
|>
select
([
p
,
u
],
%{
id:
p
.
id
,
message:
p
.
message
,
points:
p
.
points
,
user_id:
p
.
user_id
,
thread_id:
p
.
thread_id
,
parent_id:
p
.
parent_id
,
username:
u
.
username
,
inserted_at:
p
.
inserted_at
,
updated_at:
p
.
updated_at
}
)
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