Add statistiques API for dashboard
This commit is contained in:
parent
3e62dd01fb
commit
9c1268fdd5
4 changed files with 36 additions and 0 deletions
1
Gemfile
1
Gemfile
|
@ -49,6 +49,7 @@ gem 'draper'
|
||||||
#Gestion des comptes utilisateurs
|
#Gestion des comptes utilisateurs
|
||||||
gem 'devise'
|
gem 'devise'
|
||||||
gem 'openid_connect'
|
gem 'openid_connect'
|
||||||
|
|
||||||
gem 'rest-client'
|
gem 'rest-client'
|
||||||
|
|
||||||
gem 'carrierwave'
|
gem 'carrierwave'
|
||||||
|
|
19
app/controllers/api/statistiques_controller.rb
Normal file
19
app/controllers/api/statistiques_controller.rb
Normal 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
|
|
@ -116,6 +116,10 @@ Rails.application.routes.draw do
|
||||||
resources :dossiers, only: [:index, :show]
|
resources :dossiers, only: [:index, :show]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
namespace :statistiques do
|
||||||
|
get 'dossiers' => '/api/statistiques#dossiers_stats'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
apipie
|
apipie
|
||||||
|
|
12
spec/controllers/api/statistiques_spec.rb
Normal file
12
spec/controllers/api/statistiques_spec.rb
Normal 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
|
Loading…
Add table
Reference in a new issue