Bug 19234: Add query parameters handling helpers
commitcea8b9c7c5465a66cd2510117e88468259bc3983
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 1 Sep 2017 14:53:35 +0000 (1 11:53 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 11 Dec 2017 20:46:59 +0000 (11 17:46 -0300)
treea287e9af148d872843d67fbac7bc80cff009cf94
parent656efc09dc55d639258741e3b0bcfc8e38dd7dcb
Bug 19234: Add query parameters handling helpers

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

generate_dbic_query
===================

When used, it generates what's needed to perform a search on
DBIC/Koha::Objects like this:

    my $params  = $c->validation->output;
    my ($filtered_params, $reserved_params) = $c->extract_reserved_params($params);

    my $filter = do_smth($filtered_params, $reserved_params);
    my $attributes = do_smth_reserved($reserved_params);

    my $patrons = Koha::Patrons->search( $filter, $attributes );

It introduces reserved param names:
- _match
- _order_by
- _page
- _per_page

They are reserved for later usage (pagination, matching algorithm on building DB queries)

All the plugin's behaviour is tested.

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

Sponsored-by: ByWater solutions
Sponsored-by: Camden County
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Lari Taskula <lari.taskula@jns.fi>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/REST/Plugin/Query.pm [new file with mode: 0644]