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
509c96eb
Commit
509c96eb
authored
Jun 01, 2015
by
E. Kolpakov
Committed by
Saqib
Aug 04, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Filter by thread ids
parent
d9400ce5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
3 deletions
+33
-3
api/users.rb
+14
-2
spec/api/user_spec.rb
+19
-1
No files found.
api/users.rb
View file @
509c96eb
...
@@ -83,7 +83,7 @@ post "#{APIPREFIX}/users/:user_id/read" do |user_id|
...
@@ -83,7 +83,7 @@ post "#{APIPREFIX}/users/:user_id/read" do |user_id|
user
.
reload
.
to_hash
.
to_json
user
.
reload
.
to_hash
.
to_json
end
end
get
"
#{
APIPREFIX
}
/users/:user_id/social_stats"
do
|
user_id
|
def
_user_social_stats
(
user_id
,
params
)
begin
begin
return
{}.
to_json
if
not
params
[
"course_id"
]
return
{}.
to_json
if
not
params
[
"course_id"
]
...
@@ -92,6 +92,7 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
...
@@ -92,6 +92,7 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
thread_type
=
params
[
"thread_type"
]
thread_type
=
params
[
"thread_type"
]
course_id
=
params
[
"course_id"
]
course_id
=
params
[
"course_id"
]
thread_ids_filter
=
params
[
"thread_ids"
].
split
(
","
)
if
params
[
"thread_ids"
]
user_stats
=
{}
user_stats
=
{}
thread_ids
=
{}
thread_ids
=
{}
...
@@ -126,7 +127,7 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
...
@@ -126,7 +127,7 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
# as we don't need it and we shouldn't push all that data over the wire
# as we don't need it and we shouldn't push all that data over the wire
content
=
Content
.
where
(
content_selector
).
without
(
:body
)
content
=
Content
.
where
(
content_selector
).
without
(
:body
)
if
thread_type
if
thread_type
||
thread_ids_filter
thread_selector
=
{
course_id:
course_id
,
anonymous:
false
,
anonymous_to_peers:
false
}
thread_selector
=
{
course_id:
course_id
,
anonymous:
false
,
anonymous_to_peers:
false
}
if
end_date
if
end_date
thread_selector
[
:created_at
.
lte
]
=
end_date
thread_selector
[
:created_at
.
lte
]
=
end_date
...
@@ -134,6 +135,9 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
...
@@ -134,6 +135,9 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
if
thread_type
if
thread_type
thread_selector
[
"thread_type"
]
=
thread_type
thread_selector
[
"thread_type"
]
=
thread_type
end
end
if
thread_ids_filter
thread_selector
[
:commentable_id
.
in
]
=
thread_ids_filter
end
target_threads
=
CommentThread
.
where
(
thread_selector
).
only
(
:_id
).
map
(
&
:_id
)
target_threads
=
CommentThread
.
where
(
thread_selector
).
only
(
:_id
).
map
(
&
:_id
)
content
=
content
.
select
do
|
c
|
content
=
content
.
select
do
|
c
|
...
@@ -188,4 +192,12 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
...
@@ -188,4 +192,12 @@ get "#{APIPREFIX}/users/:user_id/social_stats" do |user_id|
end
end
end
end
get
"
#{
APIPREFIX
}
/users/:user_id/social_stats"
do
|
user_id
|
_user_social_stats
(
user_id
,
params
)
end
post
"
#{
APIPREFIX
}
/users/:user_id/social_stats"
do
|
user_id
|
_user_social_stats
(
user_id
,
params
)
end
spec/api/user_spec.rb
View file @
509c96eb
...
@@ -412,7 +412,7 @@ describe "app" do
...
@@ -412,7 +412,7 @@ describe "app" do
}
}
end
end
def
make_request
(
user_id
,
course_id
,
end_date
=
nil
,
thread_type
=
nil
)
def
make_request
(
user_id
,
course_id
,
end_date
=
nil
,
thread_type
=
nil
,
thread_ids
=
nil
)
parameters
=
{
:course_id
=>
course_id
}
parameters
=
{
:course_id
=>
course_id
}
if
end_date
if
end_date
parameters
[
'end_date'
]
=
end_date
parameters
[
'end_date'
]
=
end_date
...
@@ -420,6 +420,9 @@ describe "app" do
...
@@ -420,6 +420,9 @@ describe "app" do
if
thread_type
if
thread_type
parameters
[
'thread_type'
]
=
thread_type
parameters
[
'thread_type'
]
=
thread_type
end
end
if
thread_ids
parameters
[
'thread_ids'
]
=
thread_ids
.
join
(
","
)
end
get
"/api/v1/users/
#{
user_id
}
/social_stats"
,
parameters
get
"/api/v1/users/
#{
user_id
}
/social_stats"
,
parameters
...
@@ -697,6 +700,21 @@ describe "app" do
...
@@ -697,6 +700,21 @@ describe "app" do
@user2
.
id
=>
make_social_stats
(
1
,
0
,
0
,
1
,
0
,
0
,
1
,
1
,
0
),
@user2
.
id
=>
make_social_stats
(
1
,
0
,
0
,
1
,
0
,
0
,
1
,
1
,
0
),
})
})
end
end
it
"filters by thread ids"
do
check_social_stats
(
make_request
(
'*'
,
DFLT_COURSE_ID
,
nil
,
nil
,
[
"Thread 1"
]),
{
@user1
.
id
=>
make_social_stats
(
1
,
0
,
2
,
3
,
0
,
3
,
5
,
1
,
0
),
@user2
.
id
=>
make_social_stats
(
0
,
2
,
1
,
1
,
0
,
2
,
0
,
0
,
0
),
})
check_social_stats
(
make_request
(
'*'
,
DFLT_COURSE_ID
,
nil
,
nil
,
[
"Thread 2"
]),
{
@user1
.
id
=>
make_social_stats
(
0
,
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
),
@user2
.
id
=>
make_social_stats
(
2
,
1
,
0
,
4
,
0
,
1
,
2
,
3
,
0
),
})
check_social_stats
(
make_request
(
'*'
,
DFLT_COURSE_ID
,
nil
,
nil
,
[
"Thread 1"
,
"Thread 2"
]),
{
@user1
.
id
=>
make_social_stats
(
1
,
1
,
2
,
3
,
0
,
4
,
5
,
1
,
0
),
@user2
.
id
=>
make_social_stats
(
2
,
3
,
1
,
5
,
0
,
3
,
2
,
3
,
0
),
})
end
end
end
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