@@ -, +, @@ $ kshell k$ prove t/Koha/REST/Plugin/Pagination.t \ t/db_dependent/Koha/REST/Plugin/Objects.t --- Koha/REST/Plugin/Objects.pm | 22 +++++++++++++++------- Koha/REST/Plugin/Pagination.pm | 22 +++++++++++++--------- 2 files changed, 28 insertions(+), 16 deletions(-) --- a/Koha/REST/Plugin/Objects.pm +++ a/Koha/REST/Plugin/Objects.pm @@ -69,13 +69,15 @@ sub register { $reserved_params->{_per_page} //= C4::Context->preference('RESTdefaultPageSize'); $reserved_params->{_page} //= 1; - # Merge pagination into query attributes - $c->dbic_merge_pagination( - { - filter => $attributes, - params => $reserved_params - } - ); + unless ( $reserved_params->{_per_page} == -1 ) { + # Merge pagination into query attributes + $c->dbic_merge_pagination( + { + filter => $attributes, + params => $reserved_params + } + ); + } # Generate prefetches for embedded stuff $c->dbic_merge_prefetch( @@ -129,6 +131,12 @@ sub register { params => $args, }); } + else { + $c->add_pagination_headers({ + total => $objects->count, + params => $args, + }); + } return $objects->to_api({ embed => $embed }); } --- a/Koha/REST/Plugin/Pagination.pm +++ a/Koha/REST/Plugin/Pagination.pm @@ -61,20 +61,24 @@ If page size is omitted, it defaults to the value of the RESTdefaultPageSize sys my ( $c, $args ) = @_; my $total = $args->{total}; - my $req_page = $args->{params}->{_page}; + my $req_page = $args->{params}->{_page} // 1; my $per_page = $args->{params}->{_per_page} // C4::Context->preference('RESTdefaultPageSize') // 20; - # do we need to paginate? - return $c unless $req_page; - - my $pages = int $total / $per_page; - $pages++ - if $total % $per_page > 0; + my $pages; + if ( $per_page == -1 ) { + $req_page = 1; + $pages = 1; + } + else { + $pages = int $total / $per_page; + $pages++ + if $total % $per_page > 0; + } my @links; - if ( $pages > 1 and $req_page > 1 ) { # Previous exists? + if ( $per_page != -1 and $pages > 1 and $req_page > 1 ) { # Previous exists? push @links, _build_link( $c, @@ -86,7 +90,7 @@ If page size is omitted, it defaults to the value of the RESTdefaultPageSize sys ); } - if ( $pages > 1 and $req_page < $pages ) { # Next exists? + if ( $per_page != -1 and $pages > 1 and $req_page < $pages ) { # Next exists? push @links, _build_link( $c, --