Commit 916fe206 by Zia Fazal Committed by Jonathan Piacenti

api to get total and active posts for a course

allow course with slashes
parent 192da911
......@@ -93,3 +93,15 @@ delete "#{APIPREFIX}/threads/:thread_id" do |thread_id|
thread.destroy
thread.to_hash.to_json
end
get "#{APIPREFIX}/courses/*/stats" do |course_id| # retrieve stats by course
begin
threads = Content.where(_type: "CommentThread", course_id: course_id)
active_threads = threads.where(:last_activity_at.gte => 1.day.ago)
course_stats = {
"num_threads" => threads.count,
"num_active_threads" => active_threads.count
}
course_stats.to_json
end
end
......@@ -490,6 +490,31 @@ describe "app" do
parse(last_response.body).first.should == I18n.t(:requested_object_not_found)
end
# Test active and non active thread count for a course
it "test the number of active and non active threads for a course" do
User.all.delete
Content.all.delete
@user = create_test_user(999)
@threads = {}
5.times do |n|
thread_key = "t#{n}"
thread = make_thread(@user, thread_key, DFLT_COURSE_ID, "pdq")
@threads[n] = thread
end
time_threshold = 2.day.ago
@threads[0].last_activity_at = time_threshold
@threads[0].save!
@threads[1].last_activity_at = time_threshold
@threads[1].save!
get "/api/v1/courses/#{DFLT_COURSE_ID}/stats"
last_response.should be_ok
response = parse last_response.body
response["num_threads"].should == 5
response["num_active_threads"].should == 3
end
def test_unicode_data(text)
thread = make_thread(User.first, text, "unicode_course", "unicode_commentable")
make_comment(User.first, thread, text)
......
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