Commit 75bfffad by Zia Fazal Committed by Saqib

api to get total and active posts for a course

allow course with slashes
parent d3b3b3c7
......@@ -97,3 +97,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
......@@ -539,6 +539,31 @@ describe "app" do
end
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 = create(:comment_thread, body: text)
create(:comment, comment_thread: thread, body: 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