diff --git a/Gemfile b/Gemfile index 980dda77b..3c2d815a9 100644 --- a/Gemfile +++ b/Gemfile @@ -49,6 +49,7 @@ gem 'draper' #Gestion des comptes utilisateurs gem 'devise' gem 'openid_connect' + gem 'rest-client' gem 'carrierwave' diff --git a/app/controllers/api/statistiques_controller.rb b/app/controllers/api/statistiques_controller.rb new file mode 100644 index 000000000..e8263aac5 --- /dev/null +++ b/app/controllers/api/statistiques_controller.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 3048e0e9f..93183e0c7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/controllers/api/statistiques_spec.rb b/spec/controllers/api/statistiques_spec.rb new file mode 100644 index 000000000..0f3a85c39 --- /dev/null +++ b/spec/controllers/api/statistiques_spec.rb @@ -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