Add statistiques API for dashboard

This commit is contained in:
Xavier J 2016-02-29 15:15:44 +01:00
parent 3e62dd01fb
commit 9c1268fdd5
4 changed files with 36 additions and 0 deletions

View file

@ -49,6 +49,7 @@ gem 'draper'
#Gestion des comptes utilisateurs
gem 'devise'
gem 'openid_connect'
gem 'rest-client'
gem 'carrierwave'

View file

@ -0,0 +1,19 @@
class API::StatistiquesController < ApplicationController
def dossiers_stats
render json: {
total: total_dossiers,
mois: dossiers_mois
}
end
private
def total_dossiers
Dossier.all.size
end
def dossiers_mois
Dossier.where(created_at: (1.month.ago)..Time.now).size
end
end

View file

@ -116,6 +116,10 @@ Rails.application.routes.draw do
resources :dossiers, only: [:index, :show]
end
end
namespace :statistiques do
get 'dossiers' => '/api/statistiques#dossiers_stats'
end
end
apipie

View file

@ -0,0 +1,12 @@
require 'spec_helper'
describe API::StatistiquesController, type: :controller do
describe '#GET dossiers_stats' do
before do
get :dossiers_stats
end
it { expect(response.status).to eq 200 }
end
end