Commit 06c97e53 by Alan Boudreault Committed by Jonathan Piacenti

Add the ability to query multiple group ids

parent 2f78ff2e
......@@ -3,6 +3,13 @@ get "#{APIPREFIX}/threads" do # retrieve threads by course
threads = Content.where({"_type" => "CommentThread", "course_id" => params["course_id"]})
if params[:commentable_ids]
threads = threads.in({"commentable_id" => params[:commentable_ids].split(",")})
#if a group id is sent, then process the set of threads with that group id or with no group id
group_ids = get_group_ids_from_params(params)
if not group_ids.empty?
threads = threads.any_of(
{:group_id.in => group_ids},
{:group_id.exists => false},
)
end
handle_threads_query(
......
......@@ -7,6 +7,13 @@ get "#{APIPREFIX}/:commentable_id/threads" do |commentable_id|
threads = Content.where({"_type" => "CommentThread", "commentable_id" => commentable_id})
if params["course_id"]
threads = threads.where({"course_id" => params["course_id"]})
threads = Content.where(_type:"CommentThread", commentable_id: commentable_id)
group_ids = get_group_ids_from_params(params)
if not group_ids.empty?
threads = threads.any_of(
{:group_id.in => group_ids},
{:group_id.exists => false},
)
end
handle_threads_query(
......
......@@ -67,6 +67,10 @@ describe "app" do
@threads["t2"].save!
rs = thread_result course_id: "omg", group_ids: "100,101", sort_order: "asc"
rs.length.should == 2
rs.each_with_index { |res, i|
check_thread_result_json(nil, @threads["t#{i+1}"], res)
res["course_id"].should == "omg"
}
end
it "returns only threads where course id and group id match or group id is nil" do
@threads["t1"].course_id = "omg"
......
......@@ -127,7 +127,8 @@ describe "app" do
it "by group_ids" do
get "/api/v1/search/threads", text: "text", group_ids: "1,2"
expected_ids = (0..29).find_all {|i| i % 5 == 0 || i % 5 == 1 || i % 5 == 2}
expected_ids = (0..29).find_all {|i| i % 5 == 0 || i % 5 == 1}
expected_ids.concat((0..29).find_all {|i| i % 5 == 2})
assert_response_contains(expected_ids)
end
......
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