From 10950748619b3d9f672c12595acc9b6fd71d36ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Delmaire?= Date: Wed, 26 Jul 2023 11:16:35 +0200 Subject: [PATCH 1/2] API Particulier: Introduce /stats.json --- .../api_particulier/stats_controller.rb | 29 ++++++++++++++++++- .../api_particulier/stats_controller_spec.rb | 10 +++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 spec/controllers/api_particulier/stats_controller_spec.rb diff --git a/app/controllers/api_particulier/stats_controller.rb b/app/controllers/api_particulier/stats_controller.rb index 25930443e..569bbf4fd 100644 --- a/app/controllers/api_particulier/stats_controller.rb +++ b/app/controllers/api_particulier/stats_controller.rb @@ -1,5 +1,32 @@ class APIParticulier::StatsController < APIParticulierController def index - render 'index' + respond_to do |format| + format.html + format.json do + render json: data_collection + end + end + end + + private + + def data_collection + [ + { + name: 'Nombre de pièces justificatives transmises sur les 2 derniers mois', + url: 'https://metabase.entreprise.api.gouv.fr/public/question/e6d80db2-e947-4916-a487-4e040fecc511.json', + type: 'application/json' + }, + { + name: 'Nombre de quotients familiaux transmis sur les 2 derniers mois', + url: 'https://metabase.entreprise.api.gouv.fr/public/question/8d977c80-a675-48ea-9d73-294290f6665a.json', + type: 'application/json' + }, + { + name: 'Nombre de cartes étudiants transmises sur les 2 derniers mois', + url: 'https://metabase.entreprise.api.gouv.fr/public/question/a234b04f-26de-4607-b81b-fb7c5ff79b58.json', + type: 'application/json' + } + ] end end diff --git a/spec/controllers/api_particulier/stats_controller_spec.rb b/spec/controllers/api_particulier/stats_controller_spec.rb new file mode 100644 index 000000000..ad6e2a8eb --- /dev/null +++ b/spec/controllers/api_particulier/stats_controller_spec.rb @@ -0,0 +1,10 @@ +RSpec.describe APIParticulier::StatsController do + describe 'GET #index as json' do + subject(:get_index) { get :index, params: { format: :json } } + + before { get_index } + + it { is_expected.to have_http_status(:success) } + it { expect(JSON.parse(response.body)).to be_an(Array) } + end +end From 002b4570a752ba9eda617b12083426d97f96a9ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Delmaire?= Date: Wed, 26 Jul 2023 11:40:22 +0200 Subject: [PATCH 2/2] API Entreprise: introduce /stats.json --- .../api_entreprise/stats_controller.rb | 29 ++++++++++++++++++- .../api_entreprise/stats_controller_spec.rb | 10 +++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 spec/controllers/api_entreprise/stats_controller_spec.rb diff --git a/app/controllers/api_entreprise/stats_controller.rb b/app/controllers/api_entreprise/stats_controller.rb index 1c1453e8c..9bf15dfa8 100644 --- a/app/controllers/api_entreprise/stats_controller.rb +++ b/app/controllers/api_entreprise/stats_controller.rb @@ -1,5 +1,32 @@ class APIEntreprise::StatsController < APIEntrepriseController def index - render 'index' + respond_to do |format| + format.html + format.json do + render json: data_collection + end + end + end + + private + + def data_collection + [ + { + name: 'Nombre d\'appels pour une unité légale sur les 2 derniers mois', + url: 'https://metabase.entreprise.api.gouv.fr/public/question/021a0118-2071-416c-8527-e76e350b1d03.json', + type: 'application/json' + }, + { + name: 'Nombre d\'appels totaux sur les 2 derniers mois', + url: 'https://metabase.entreprise.api.gouv.fr/public/question/b3923a04-55d3-4c79-a035-201a6d0e2d13.json', + type: 'application/json' + }, + { + name: 'Nombre d\'appels uniques sur les 2 derniers mois', + url: 'https://metabase.entreprise.api.gouv.fr/public/question/f62b61aa-227e-4f0e-b9f0-605913771cde.json', + type: 'application/json' + } + ] end end diff --git a/spec/controllers/api_entreprise/stats_controller_spec.rb b/spec/controllers/api_entreprise/stats_controller_spec.rb new file mode 100644 index 000000000..f49ee0afc --- /dev/null +++ b/spec/controllers/api_entreprise/stats_controller_spec.rb @@ -0,0 +1,10 @@ +RSpec.describe APIEntreprise::StatsController do + describe 'GET #index as json' do + subject(:get_index) { get :index, params: { format: :json } } + + before { get_index } + + it { is_expected.to have_http_status(:success) } + it { expect(JSON.parse(response.body)).to be_an(Array) } + end +end