Commit cdd8b785 by David Ormsbee

Merge pull request #20 from rll/feature/kevin/groups

Feature/kevin/groups
parents e812883b 5cbf0690
......@@ -33,3 +33,4 @@ log/
#redcar
.redcar/
/nbproject
\ No newline at end of file
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
get "#{APIPREFIX}/threads/:thread_id" do |thread_id|
......@@ -14,7 +24,8 @@ get "#{APIPREFIX}/threads/:thread_id" do |thread_id|
end
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"]
thread.tags = params["tags"]
thread.save
......
......@@ -4,16 +4,27 @@ delete "#{APIPREFIX}/:commentable_id/threads" do |commentable_id|
end
get "#{APIPREFIX}/:commentable_id/threads" do |commentable_id|
handle_threads_query(commentable.comment_threads)
if params["group_id"]
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
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_to_peers = bool_anonymous_to_peers || false
thread.tags = params["tags"] || ""
if params["group_id"]
thread.group_id = params["group_id"]
end
thread.author = user
thread.save
if thread.errors.any?
......
......@@ -21,6 +21,7 @@ class CommentThread < Content
field :closed, type: Boolean, default: false
field :at_position_list, type: Array, default: []
field :last_activity_at, type: Time
field :group_id, type: Integer
index({author_id: 1, course_id: 1})
......@@ -39,9 +40,10 @@ class CommentThread < Content
indexes :comment_count, type: :integer, 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 :commentable_id, type: :string, index: :not_analyzed, incldued_in_all: false
indexes :author_id, type: :string, as: 'author_id', 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, included_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
belongs_to :author, class_name: "User", inverse_of: :comment_threads, index: true#, autosave: true
......@@ -107,14 +109,27 @@ class CommentThread < Content
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(: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.size per_page
search.from per_page * (page - 1)
results = search.results
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
search.results
results
end
def activity_since(from_time=nil)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment