|
Line 0
Link Here
|
| 0 |
- |
1 |
package Koha::REST::Plugin::Query; |
|
|
2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it under the |
| 6 |
# terms of the GNU General Public License as published by the Free Software |
| 7 |
# Foundation; either version 3 of the License, or (at your option) any later |
| 8 |
# version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
| 12 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License along |
| 15 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
| 16 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 |
|
| 18 |
use Modern::Perl; |
| 19 |
|
| 20 |
use Mojo::Base 'Mojolicious::Plugin'; |
| 21 |
|
| 22 |
=head1 NAME |
| 23 |
|
| 24 |
Koha::REST::Plugin::Query |
| 25 |
|
| 26 |
=head1 API |
| 27 |
|
| 28 |
=head2 Mojolicious::Plugin methods |
| 29 |
|
| 30 |
=head3 register |
| 31 |
|
| 32 |
=cut |
| 33 |
|
| 34 |
sub register { |
| 35 |
my ( $self, $app ) = @_; |
| 36 |
|
| 37 |
=head2 Helper methods |
| 38 |
|
| 39 |
=head3 extract_reserved_params |
| 40 |
|
| 41 |
my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($params); |
| 42 |
|
| 43 |
Generates the DBIC query from the query parameters. |
| 44 |
|
| 45 |
=cut |
| 46 |
|
| 47 |
$app->helper( |
| 48 |
'extract_reserved_params' => sub { |
| 49 |
my ( $c, $params ) = @_; |
| 50 |
|
| 51 |
my $reserved_params; |
| 52 |
my $filtered_params; |
| 53 |
|
| 54 |
my $reserved_words = _reserved_words(); |
| 55 |
|
| 56 |
foreach my $param ( keys %{$params} ) { |
| 57 |
if ( grep { $param eq $_ } @{$reserved_words} ) { |
| 58 |
$reserved_params->{$param} = $params->{$param}; |
| 59 |
} |
| 60 |
else { |
| 61 |
$filtered_params->{$param} = $params->{$param}; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
return ( $filtered_params, $reserved_params ); |
| 66 |
} |
| 67 |
); |
| 68 |
} |
| 69 |
|
| 70 |
=head2 Internal methods |
| 71 |
|
| 72 |
=head3 _reserved_words |
| 73 |
|
| 74 |
my $reserved_words = _reserved_words(); |
| 75 |
|
| 76 |
=cut |
| 77 |
|
| 78 |
sub _reserved_words { |
| 79 |
|
| 80 |
my @reserved_words = qw( _match _order_by _page _per_page ); |
| 81 |
return \@reserved_words; |
| 82 |
} |
| 83 |
|
| 84 |
1; |