diff --git a/CHANGELOG.md b/CHANGELOG.md index ad97d0f..9cdf683 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ + * Add site_stats call to API * Fix bug in response user_generated_ideas totals over time, where the min and max dates were getting added as strings instead of date objects * Update choices to act_as_versioned diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index 40ca5a2..bafd2bd 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -326,6 +326,21 @@ class QuestionsController < InheritedResources::Base update! end + def site_stats + results = Question.connection.select_one("SELECT COUNT(*) as total_questions, SUM(votes_count) as votes_count, SUM(choices_count) choices_count FROM questions where site_id = #{current_user.id}") + results.each do |key, value| + results[key] = value.to_i + end + respond_to do |format| + format.xml { + render :xml => results.to_xml + } + format.js{ + render :json => results.to_json + } + end + end + def index counts = {} diff --git a/config/routes.rb b/config/routes.rb index 0bb7bd7..cf2c1a5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,6 +14,7 @@ ActionController::Routing::Routes.draw do |map| :export => :post} , :collection => {:all_num_votes_by_visitor_id => :get, :all_object_info_totals_by_date => :get, + :site_stats => :get, :object_info_totals_by_question_id => :get, :recent_votes_by_question_id => :get} do |question| question.resources :prompts, :only => :show, diff --git a/spec/integration/questions_spec.rb b/spec/integration/questions_spec.rb index e710261..0686269 100644 --- a/spec/integration/questions_spec.rb +++ b/spec/integration/questions_spec.rb @@ -11,6 +11,16 @@ describe "Questions" do end end + describe "GET 'site_stats'" do + it "should return site_stats" do + Factory.create(:vote, :question => @questions.first) + get_auth site_stats_questions_path(:format => 'xml') + response.should be_success + response.body.should have_tag("total-questions", :text => @questions.count) + response.body.should have_tag("votes-count", :text => 1) + end + end + describe "GET 'median_votes_per_session'" do it "should return the median" do Factory.create(:vote, :question => @questions.first) -- libgit2 0.21.2