Bug 19196: Add Koha::REST::Plugin::Pagination
authorTomas Cohen Arazi <tomascohen@theke.io>
Tue, 29 Aug 2017 19:52:48 +0000 (16:52 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 9 Oct 2017 19:15:51 +0000 (16:15 -0300)
commit26f3ca8d88486e5948c400f0d19d8c5bdf392d2e
treebc52f487f2ce23b5301df78c23385ef60ef0984d
parentb811dbbd8d8cdbe226bf123bc52daff426eac72f
Bug 19196: Add Koha::REST::Plugin::Pagination

This patch introduces a Mojolicious plugin to be used on the REST api.
It adds a helper method:

add_pagination_headers
======================

When used, it adds a _Link_ header to the reponse with the calculated
values for pagination, and X-Total-Count containing the total results
like this:

    my $params  = $c->validation->output;
    my $patrons = Koha::Patrons->search;
    my $count   = $patrons->count;

    $c->add_pagination_headers({
            total  => $count,
            params => $params )};

To test:
- Run:
  $ sudo koha-shell kohadev
 k$ cd kohaclone
 k$ prove t/Koha/REST/Plugin/Pagination.t
=> SUCCESS: Tests pass!
- Sign off :-D

Sponsored-by: ByWater solutions
Sponsored-by: Camden County
Edit: I fixed a mistake on the POD (tcohen)

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Lari Taskula <lari.taskula@jns.fi>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/REST/Plugin/Pagination.pm [new file with mode: 0644]