Document pagination params in api and allow to set per_page limit

This commit is contained in:
Paul Chavard 2018-03-08 17:42:12 +01:00 committed by Frederic Merizen
parent 87d1948023
commit e4f07dbae6
2 changed files with 6 additions and 2 deletions

View file

@ -1,6 +1,10 @@
class API::V1::DossiersController < APIController
DEFAULT_PAGE_SIZE = 100
api :GET, '/procedures/:procedure_id/dossiers/', 'Liste de tous les dossiers d\'une procédure'
param :procedure_id, Integer, desc: "L'identifiant de la procédure", required: true
param :page, String, desc: "Numéro de la page", required: false
param :resultats_par_page, String, desc: "Nombre de résultats par page (#{DEFAULT_PAGE_SIZE} par défaut, maximum 1 000)", required: false
error code: 401, desc: "Non authorisé"
error code: 404, desc: "Procédure inconnue"
@ -39,6 +43,6 @@ class API::V1::DossiersController < APIController
end
def per_page # inherited value from will_paginate
12
[params[:resultats_par_page] || DEFAULT_PAGE_SIZE, 1000].min
end
end

View file

@ -56,7 +56,7 @@ describe API::V1::DossiersController do
it { is_expected.to have_key(:page) }
it { expect(subject[:page]).to eq(1) }
it { is_expected.to have_key(:resultats_par_page) }
it { expect(subject[:resultats_par_page]).to eq(12) }
it { expect(subject[:resultats_par_page]).to eq(described_class.const_get(:DEFAULT_PAGE_SIZE)) }
it { is_expected.to have_key(:nombre_de_page) }
it { expect(subject[:nombre_de_page]).to eq(1) }
end