Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cs_comments_service
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
cs_comments_service
Commits
353a6981
Commit
353a6981
authored
Aug 01, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pagination for threads
parent
8b0ccc0c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
4 deletions
+18
-4
app.rb
+12
-1
spec/api/commentable_spec.rb
+6
-3
No files found.
app.rb
View file @
353a6981
...
@@ -25,6 +25,7 @@ get '/api/v1/search/threads' do
...
@@ -25,6 +25,7 @@ get '/api/v1/search/threads' do
CommentThread
.
solr_search
do
CommentThread
.
solr_search
do
fulltext
(
params
[
"text"
])
if
params
[
"text"
]
fulltext
(
params
[
"text"
])
if
params
[
"text"
]
with
(
:commentable_id
,
params
[
"commentable_id"
])
if
params
[
"commentable_id"
]
with
(
:commentable_id
,
params
[
"commentable_id"
])
if
params
[
"commentable_id"
]
with
(
:course_id
,
params
[
"course_id"
])
if
params
[
"course_id"
]
with
(
:tags
).
all_of
(
params
[
"tags"
].
split
/,/
)
if
params
[
"tags"
]
with
(
:tags
).
all_of
(
params
[
"tags"
].
split
/,/
)
if
params
[
"tags"
]
end
.
results
.
map
(
&
:to_hash
).
to_json
end
.
results
.
map
(
&
:to_hash
).
to_json
end
end
...
@@ -35,7 +36,17 @@ delete '/api/v1/:commentable_id/threads' do |commentable_id|
...
@@ -35,7 +36,17 @@ delete '/api/v1/:commentable_id/threads' do |commentable_id|
end
end
get
'/api/v1/:commentable_id/threads'
do
|
commentable_id
|
get
'/api/v1/:commentable_id/threads'
do
|
commentable_id
|
commentable
.
comment_threads
.
map
{
|
t
|
t
.
to_hash
(
recursive:
value_to_boolean
(
params
[
"recursive"
]))}.
to_json
page
=
(
params
[
"page"
]
||
1
).
to_i
per_page
=
(
params
[
"per_page"
]
||
20
).
to_i
comment_threads
=
commentable
.
comment_threads
num_pages
=
[
1
,
(
comment_threads
.
count
/
per_page
.
to_f
).
ceil
].
max
page
=
[
num_pages
,
[
1
,
page
].
max
].
min
{
collection:
comment_threads
.
page
(
page
).
per
(
per_page
).
map
{
|
t
|
t
.
to_hash
(
recursive:
value_to_boolean
(
params
[
"recursive"
]))},
num_pages:
num_pages
,
per_page:
per_page
,
page:
page
,
}.
to_json
end
end
post
'/api/v1/:commentable_id/threads'
do
|
commentable_id
|
post
'/api/v1/:commentable_id/threads'
do
|
commentable_id
|
...
...
spec/api/commentable_spec.rb
View file @
353a6981
...
@@ -18,7 +18,8 @@ describe "app" do
...
@@ -18,7 +18,8 @@ describe "app" do
it
"get all comment threads associated with a commentable object"
do
it
"get all comment threads associated with a commentable object"
do
get
"/api/v1/question_1/threads"
get
"/api/v1/question_1/threads"
last_response
.
should
be_ok
last_response
.
should
be_ok
threads
=
parse
last_response
.
body
response
=
parse
last_response
.
body
threads
=
response
[
'collection'
]
threads
.
length
.
should
==
2
threads
.
length
.
should
==
2
threads
.
index
{
|
c
|
c
[
"body"
]
==
"can anyone help me?"
}.
should_not
be_nil
threads
.
index
{
|
c
|
c
[
"body"
]
==
"can anyone help me?"
}.
should_not
be_nil
threads
.
index
{
|
c
|
c
[
"body"
]
==
"it is unsolvable"
}.
should_not
be_nil
threads
.
index
{
|
c
|
c
[
"body"
]
==
"it is unsolvable"
}.
should_not
be_nil
...
@@ -26,7 +27,8 @@ describe "app" do
...
@@ -26,7 +27,8 @@ describe "app" do
it
"get all comment threads and comments associated with a commentable object"
do
it
"get all comment threads and comments associated with a commentable object"
do
get
"/api/v1/question_1/threads"
,
recursive:
true
get
"/api/v1/question_1/threads"
,
recursive:
true
last_response
.
should
be_ok
last_response
.
should
be_ok
threads
=
parse
last_response
.
body
response
=
parse
last_response
.
body
threads
=
response
[
'collection'
]
threads
.
length
.
should
==
2
threads
.
length
.
should
==
2
threads
.
index
{
|
c
|
c
[
"body"
]
==
"can anyone help me?"
}.
should_not
be_nil
threads
.
index
{
|
c
|
c
[
"body"
]
==
"can anyone help me?"
}.
should_not
be_nil
threads
.
index
{
|
c
|
c
[
"body"
]
==
"it is unsolvable"
}.
should_not
be_nil
threads
.
index
{
|
c
|
c
[
"body"
]
==
"it is unsolvable"
}.
should_not
be_nil
...
@@ -45,7 +47,8 @@ describe "app" do
...
@@ -45,7 +47,8 @@ describe "app" do
it
"returns an empty array when the commentable object does not exist (no threads)"
do
it
"returns an empty array when the commentable object does not exist (no threads)"
do
get
"/api/v1/does_not_exist/threads"
get
"/api/v1/does_not_exist/threads"
last_response
.
should
be_ok
last_response
.
should
be_ok
threads
=
parse
last_response
.
body
response
=
parse
last_response
.
body
threads
=
response
[
'collection'
]
threads
.
length
.
should
==
0
threads
.
length
.
should
==
0
end
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