From 7c82c9793062b93c463798db0fd606fbd2905d56 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 25 Sep 2017 15:01:51 -0300 Subject: [PATCH] Bug 19196: Rename page and per_page This patch just renames 'page' and 'per_page' params, for '_page' and '_per_page' respectively. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Lari Taskula Signed-off-by: Jonathan Druart --- Koha/REST/Plugin/Pagination.pm | 12 ++++----- t/Koha/REST/Plugin/Pagination.t | 46 ++++++++++++++++----------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Koha/REST/Plugin/Pagination.pm b/Koha/REST/Plugin/Pagination.pm index 8b09dd1c84..5f5b7eb50a 100644 --- a/Koha/REST/Plugin/Pagination.pm +++ b/Koha/REST/Plugin/Pagination.pm @@ -42,8 +42,8 @@ sub register { $c->add_pagination_headers({ total => $patrons->count, params => { - page => ... - per_page => ... + _page => ... + _per_page => ... ... } }); @@ -59,8 +59,8 @@ It also adds X-Total-Count, containing the total results count. my ( $c, $args ) = @_; my $total = $args->{total}; - my $req_page = $args->{params}->{page}; - my $per_page = $args->{params}->{per_page}; + my $req_page = $args->{params}->{_page}; + my $per_page = $args->{params}->{_per_page}; my $pages = int $total / $per_page; $pages++ @@ -124,8 +124,8 @@ sub _build_link { my $params = $args->{params}; - $params->{page} = $args->{page}; - $params->{per_page} = $args->{per_page}; + $params->{_page} = $args->{page}; + $params->{_per_page} = $args->{per_page}; my $link = '<' . $c->req->url->clone->query( diff --git a/t/Koha/REST/Plugin/Pagination.t b/t/Koha/REST/Plugin/Pagination.t index 04d51e1f44..586b3733c8 100644 --- a/t/Koha/REST/Plugin/Pagination.t +++ b/t/Koha/REST/Plugin/Pagination.t @@ -32,19 +32,19 @@ get '/empty' => sub { get '/pagination_headers' => sub { my $c = shift; - $c->add_pagination_headers({ total => 10, params => { page => 2, per_page => 3, firstname => 'Jonathan' } }); + $c->add_pagination_headers({ total => 10, params => { _page => 2, _per_page => 3, firstname => 'Jonathan' } }); $c->render( json => { ok => 1 }, status => 200 ); }; get '/pagination_headers_first_page' => sub { my $c = shift; - $c->add_pagination_headers({ total => 10, params => { page => 1, per_page => 3, firstname => 'Jonathan' } }); + $c->add_pagination_headers({ total => 10, params => { _page => 1, _per_page => 3, firstname => 'Jonathan' } }); $c->render( json => { ok => 1 }, status => 200 ); }; get '/pagination_headers_last_page' => sub { my $c = shift; - $c->add_pagination_headers({ total => 10, params => { page => 4, per_page => 3, firstname => 'Jonathan' } }); + $c->add_pagination_headers({ total => 10, params => { _page => 4, _per_page => 3, firstname => 'Jonathan' } }); $c->render( json => { ok => 1 }, status => 200 ); }; @@ -67,44 +67,44 @@ subtest 'add_pagination_headers() tests' => sub { $t->get_ok('/pagination_headers') ->status_is( 200 ) ->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' ) - ->header_like( 'Link' => qr/; rel="prev",/ ) - ->header_like( 'Link' => qr/; rel="prev",/ ) + ->header_like( 'Link' => qr/; rel="prev",/ ) + ->header_like( 'Link' => qr/; rel="prev",/ ) ->header_like( 'Link' => qr/; rel="prev",/ ) - ->header_like( 'Link' => qr/; rel="next",/ ) - ->header_like( 'Link' => qr/; rel="next",/ ) + ->header_like( 'Link' => qr/; rel="next",/ ) + ->header_like( 'Link' => qr/; rel="next",/ ) ->header_like( 'Link' => qr/; rel="next",/ ) - ->header_like( 'Link' => qr/; rel="first",/ ) - ->header_like( 'Link' => qr/; rel="first",/ ) + ->header_like( 'Link' => qr/; rel="first",/ ) + ->header_like( 'Link' => qr/; rel="first",/ ) ->header_like( 'Link' => qr/; rel="first",/ ) - ->header_like( 'Link' => qr/; rel="last"/ ) - ->header_like( 'Link' => qr/; rel="last"/ ) + ->header_like( 'Link' => qr/; rel="last"/ ) + ->header_like( 'Link' => qr/; rel="last"/ ) ->header_like( 'Link' => qr/; rel="last"/ ); $t->get_ok('/pagination_headers_first_page') ->status_is( 200 ) ->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' ) ->header_unlike( 'Link' => qr/; rel="prev",/ ) - ->header_like( 'Link' => qr/; rel="next",/ ) - ->header_like( 'Link' => qr/; rel="next",/ ) + ->header_like( 'Link' => qr/; rel="next",/ ) + ->header_like( 'Link' => qr/; rel="next",/ ) ->header_like( 'Link' => qr/; rel="next",/ ) - ->header_like( 'Link' => qr/; rel="first",/ ) - ->header_like( 'Link' => qr/; rel="first",/ ) + ->header_like( 'Link' => qr/; rel="first",/ ) + ->header_like( 'Link' => qr/; rel="first",/ ) ->header_like( 'Link' => qr/; rel="first",/ ) - ->header_like( 'Link' => qr/; rel="last"/ ) - ->header_like( 'Link' => qr/; rel="last"/ ) + ->header_like( 'Link' => qr/; rel="last"/ ) + ->header_like( 'Link' => qr/; rel="last"/ ) ->header_like( 'Link' => qr/; rel="last"/ ); $t->get_ok('/pagination_headers_last_page') ->status_is( 200 ) ->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' ) - ->header_like( 'Link' => qr/; rel="prev",/ ) - ->header_like( 'Link' => qr/; rel="prev",/ ) + ->header_like( 'Link' => qr/; rel="prev",/ ) + ->header_like( 'Link' => qr/; rel="prev",/ ) ->header_like( 'Link' => qr/; rel="prev",/ ) ->header_unlike( 'Link' => qr/; rel="next",/ ) - ->header_like( 'Link' => qr/; rel="first",/ ) - ->header_like( 'Link' => qr/; rel="first",/ ) + ->header_like( 'Link' => qr/; rel="first",/ ) + ->header_like( 'Link' => qr/; rel="first",/ ) ->header_like( 'Link' => qr/; rel="first",/ ) - ->header_like( 'Link' => qr/; rel="last"/ ) - ->header_like( 'Link' => qr/; rel="last"/ ) + ->header_like( 'Link' => qr/; rel="last"/ ) + ->header_like( 'Link' => qr/; rel="last"/ ) ->header_like( 'Link' => qr/; rel="last"/ ); }; -- 2.39.5