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
caa42cb4
Commit
caa42cb4
authored
Mar 06, 2015
by
E. Kolpakov
Committed by
Jonathan Piacenti
Aug 12, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for social_stats endpoint; added ability to filter by thread type
parent
1e54a129
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
14 deletions
+27
-14
api/users.rb
+27
-14
spec/api/user_spec.rb
+0
-0
No files found.
api/users.rb
View file @
caa42cb4
...
...
@@ -84,26 +84,20 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
# parse the optional "end" date filter passed in by the caller
end_date
=
DateTime
.
iso8601
(
params
[
"end_date"
])
if
params
[
"end_date"
]
thread_type
=
params
[
"thread_type"
]
course_id
=
params
[
"course_id"
]
user_stats
=
{}
thread_ids
=
{}
# get all metadata regarding forum content, but don't bother to fetch the body
# as we don't need it and we shouldn't push all that data over the wire
if
user_id
==
"*"
then
if
end_date
then
content
=
Content
.
where
(
course_id:
course_id
,
anonymous:
false
,
anonymous_to_peers:
false
,
:created_at
.
lte
=>
(
end_date
)).
without
(
:body
)
else
content
=
Content
.
where
(
course_id:
course_id
,
anonymous:
false
,
anonymous_to_peers:
false
).
without
(
:body
)
end
else
if
end_date
then
content
=
Content
.
where
(
author_id:
user_id
,
course_id:
course_id
,
anonymous:
false
,
anonymous_to_peers:
false
,
:created_at
.
lte
=>
(
end_date
)).
without
(
:body
)
else
content
=
Content
.
where
(
author_id:
user_id
,
course_id:
course_id
,
anonymous:
false
,
anonymous_to_peers:
false
).
without
(
:body
)
end
content_selector
=
{
course_id:
course_id
,
anonymous:
false
,
anonymous_to_peers:
false
}
if
end_date
content_selector
[
:created_at
.
lte
]
=
end_date
end
if
user_id
!=
'*'
content_selector
[
"author_id"
]
=
user_id
user_stats
[
user_id
]
=
{
"num_threads"
=>
0
,
"num_comments"
=>
0
,
...
...
@@ -116,6 +110,25 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
thread_ids
[
user_id
]
=
[]
end
# get all metadata regarding forum content, but don't bother to fetch the body
# as we don't need it and we shouldn't push all that data over the wire
content
=
Content
.
where
(
content_selector
).
without
(
:body
)
if
thread_type
thread_selector
=
{
course_id:
course_id
,
anonymous:
false
,
anonymous_to_peers:
false
}
if
end_date
thread_selector
[
:created_at
.
lte
]
=
end_date
end
if
thread_type
thread_selector
[
"thread_type"
]
=
thread_type
end
target_threads
=
CommentThread
.
where
(
thread_selector
).
only
(
:_id
).
map
(
&
:_id
)
content
=
content
.
select
do
|
c
|
(
c
.
_type
==
"CommentThread"
&&
c
.
thread_type
==
thread_type
)
||
target_threads
.
include?
(
c
.
comment_thread_id
)
end
end
content
.
each
do
|
item
|
user_id
=
item
.
author_id
...
...
spec/api/user_spec.rb
View file @
caa42cb4
This diff is collapsed.
Click to expand it.
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