API v1 correctly handle resultats_par_page

This commit is contained in:
Paul Chavard 2019-11-05 16:36:12 +01:00
parent d91d1d9fa8
commit 95f98fe605

View file

@ -2,6 +2,7 @@ class API::V1::DossiersController < APIController
before_action :fetch_procedure_and_check_token
DEFAULT_PAGE_SIZE = 100
MAX_PAGE_SIZE = 1000
ORDER_DIRECTIONS = { 'asc' => :asc, 'desc' => :desc }
def index
@ -33,7 +34,12 @@ class API::V1::DossiersController < APIController
end
def per_page # inherited value from will_paginate
[params[:resultats_par_page]&.to_i || DEFAULT_PAGE_SIZE, 1000].min
resultats_par_page = params[:resultats_par_page]&.to_i
if resultats_par_page && resultats_par_page > 0
[resultats_par_page, MAX_PAGE_SIZE].min
else
DEFAULT_PAGE_SIZE
end
end
def fetch_procedure_and_check_token