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
cdd8b785
Commit
cdd8b785
authored
Jan 25, 2013
by
David Ormsbee
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #20 from rll/feature/kevin/groups
Feature/kevin/groups
parents
e812883b
5cbf0690
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
12 deletions
+51
-12
.gitignore
+2
-0
api/comment_threads.rb
+14
-3
api/commentables.rb
+15
-4
models/comment_thread.rb
+20
-5
No files found.
.gitignore
View file @
cdd8b785
...
@@ -33,3 +33,4 @@ log/
...
@@ -33,3 +33,4 @@ log/
#redcar
#redcar
.redcar/
.redcar/
/nbproject
\ No newline at end of file
api/comment_threads.rb
View file @
cdd8b785
get
"
#{
APIPREFIX
}
/threads"
do
# retrieve threads by course
get
"
#{
APIPREFIX
}
/threads"
do
# retrieve threads by course
handle_threads_query
(
CommentThread
.
where
(
course_id:
params
[
"course_id"
]))
#if a group id is sent, then process the set of threads with that group id or with no group id
if
params
[
"group_id"
]
threads
=
CommentThread
.
any_of
(
{
:course_id
=>
params
[
"course_id"
],
:group_id
=>
params
[
:group_id
]},
{
:course_id
=>
params
[
"course_id"
],
:group_id
.
exists
=>
false
},
)
else
threads
=
CommentThread
.
where
(
course_id:
params
[
"course_id"
])
#else process them all
end
handle_threads_query
(
threads
)
end
end
get
"
#{
APIPREFIX
}
/threads/:thread_id"
do
|
thread_id
|
get
"
#{
APIPREFIX
}
/threads/:thread_id"
do
|
thread_id
|
...
@@ -14,12 +24,13 @@ get "#{APIPREFIX}/threads/:thread_id" do |thread_id|
...
@@ -14,12 +24,13 @@ get "#{APIPREFIX}/threads/:thread_id" do |thread_id|
end
end
put
"
#{
APIPREFIX
}
/threads/:thread_id"
do
|
thread_id
|
put
"
#{
APIPREFIX
}
/threads/:thread_id"
do
|
thread_id
|
thread
.
update_attributes
(
params
.
slice
(
*
%w[title body closed commentable_id]
))
thread
.
update_attributes
(
params
.
slice
(
*
%w[title body closed commentable_id group_id]
))
if
params
[
"tags"
]
if
params
[
"tags"
]
thread
.
tags
=
params
[
"tags"
]
thread
.
tags
=
params
[
"tags"
]
thread
.
save
thread
.
save
end
end
if
thread
.
errors
.
any?
if
thread
.
errors
.
any?
error
400
,
thread
.
errors
.
full_messages
.
to_json
error
400
,
thread
.
errors
.
full_messages
.
to_json
else
else
...
...
api/commentables.rb
View file @
cdd8b785
...
@@ -4,16 +4,27 @@ delete "#{APIPREFIX}/:commentable_id/threads" do |commentable_id|
...
@@ -4,16 +4,27 @@ delete "#{APIPREFIX}/:commentable_id/threads" do |commentable_id|
end
end
get
"
#{
APIPREFIX
}
/:commentable_id/threads"
do
|
commentable_id
|
get
"
#{
APIPREFIX
}
/:commentable_id/threads"
do
|
commentable_id
|
if
params
[
"group_id"
]
handle_threads_query
(
commentable
.
comment_threads
)
threads
=
CommentThread
.
any_of
(
{
:commentable_id
=>
commentable_id
,
:group_id
=>
params
[
:group_id
]},
{
:commentable_id
=>
commentable_id
,
:group_id
.
exists
=>
false
},
)
else
threads
=
commentable
.
comment_threads
end
handle_threads_query
(
threads
)
end
end
post
"
#{
APIPREFIX
}
/:commentable_id/threads"
do
|
commentable_id
|
post
"
#{
APIPREFIX
}
/:commentable_id/threads"
do
|
commentable_id
|
thread
=
CommentThread
.
new
(
params
.
slice
(
*
%w[title body course_id]
).
merge
(
commentable_id:
commentable_id
))
thread
=
CommentThread
.
new
(
params
.
slice
(
*
%w[title body course_id
]
).
merge
(
commentable_id:
commentable_id
))
thread
.
anonymous
=
bool_anonymous
||
false
thread
.
anonymous
=
bool_anonymous
||
false
thread
.
anonymous_to_peers
=
bool_anonymous_to_peers
||
false
thread
.
anonymous_to_peers
=
bool_anonymous_to_peers
||
false
thread
.
tags
=
params
[
"tags"
]
||
""
thread
.
tags
=
params
[
"tags"
]
||
""
if
params
[
"group_id"
]
thread
.
group_id
=
params
[
"group_id"
]
end
thread
.
author
=
user
thread
.
author
=
user
thread
.
save
thread
.
save
if
thread
.
errors
.
any?
if
thread
.
errors
.
any?
...
...
models/comment_thread.rb
View file @
cdd8b785
...
@@ -21,6 +21,7 @@ class CommentThread < Content
...
@@ -21,6 +21,7 @@ class CommentThread < Content
field
:closed
,
type:
Boolean
,
default:
false
field
:closed
,
type:
Boolean
,
default:
false
field
:at_position_list
,
type:
Array
,
default:
[]
field
:at_position_list
,
type:
Array
,
default:
[]
field
:last_activity_at
,
type:
Time
field
:last_activity_at
,
type:
Time
field
:group_id
,
type:
Integer
index
({
author_id:
1
,
course_id:
1
})
index
({
author_id:
1
,
course_id:
1
})
...
@@ -39,9 +40,10 @@ class CommentThread < Content
...
@@ -39,9 +40,10 @@ class CommentThread < Content
indexes
:comment_count
,
type: :integer
,
included_in_all:
false
indexes
:comment_count
,
type: :integer
,
included_in_all:
false
indexes
:votes_point
,
type: :integer
,
as:
'votes_point'
,
included_in_all:
false
indexes
:votes_point
,
type: :integer
,
as:
'votes_point'
,
included_in_all:
false
indexes
:course_id
,
type: :string
,
index: :not_analyzed
,
incldued_in_all:
false
indexes
:course_id
,
type: :string
,
index: :not_analyzed
,
included_in_all:
false
indexes
:commentable_id
,
type: :string
,
index: :not_analyzed
,
incldued_in_all:
false
indexes
:commentable_id
,
type: :string
,
index: :not_analyzed
,
included_in_all:
false
indexes
:author_id
,
type: :string
,
as:
'author_id'
,
index: :not_analyzed
,
incldued_in_all:
false
indexes
:author_id
,
type: :string
,
as:
'author_id'
,
index: :not_analyzed
,
included_in_all:
false
indexes
:group_id
,
type: :integer
,
as:
'group_id'
,
index: :not_analyzed
,
included_in_all:
false
end
end
belongs_to
:author
,
class_name:
"User"
,
inverse_of: :comment_threads
,
index:
true
#, autosave: true
belongs_to
:author
,
class_name:
"User"
,
inverse_of: :comment_threads
,
index:
true
#, autosave: true
...
@@ -107,14 +109,27 @@ class CommentThread < Content
...
@@ -107,14 +109,27 @@ class CommentThread < Content
search
.
filter
(
:term
,
commentable_id:
params
[
"commentable_id"
])
if
params
[
"commentable_id"
]
search
.
filter
(
:term
,
commentable_id:
params
[
"commentable_id"
])
if
params
[
"commentable_id"
]
search
.
filter
(
:terms
,
commentable_id:
params
[
"commentable_ids"
])
if
params
[
"commentable_ids"
]
search
.
filter
(
:terms
,
commentable_id:
params
[
"commentable_ids"
])
if
params
[
"commentable_ids"
]
search
.
filter
(
:term
,
course_id:
params
[
"course_id"
])
if
params
[
"course_id"
]
search
.
filter
(
:term
,
course_id:
params
[
"course_id"
])
if
params
[
"course_id"
]
if
params
[
"group_id"
]
search
.
filter
:or
,
[
{
:not
=>
{
:exists
=>
{
:field
=>
:group_id
}}},
{
:term
=>
{
:group_id
=>
params
[
"group_id"
]}}
]
end
search
.
sort
{
|
sort
|
sort
.
by
sort_key
,
sort_order
}
if
sort_key
&&
sort_order
#TODO should have search option 'auto sort or sth'
search
.
sort
{
|
sort
|
sort
.
by
sort_key
,
sort_order
}
if
sort_key
&&
sort_order
#TODO should have search option 'auto sort or sth'
search
.
size
per_page
search
.
size
per_page
search
.
from
per_page
*
(
page
-
1
)
search
.
from
per_page
*
(
page
-
1
)
results
=
search
.
results
if
CommentService
.
config
[
:cache_enabled
]
if
CommentService
.
config
[
:cache_enabled
]
Sinatra
::
Application
.
cache
.
set
(
memcached_key
,
search
.
results
,
CommentService
.
config
[
:cache_timeout
][
:threads_search
].
to_i
)
Sinatra
::
Application
.
cache
.
set
(
memcached_key
,
results
,
CommentService
.
config
[
:cache_timeout
][
:threads_search
].
to_i
)
end
end
search
.
results
results
end
end
def
activity_since
(
from_time
=
nil
)
def
activity_since
(
from_time
=
nil
)
...
...
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