1 package Koha::REST::V1::Illrequests;
3 # This file is part of Koha.
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
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.
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.
20 use Mojo::Base 'Mojolicious::Controller';
22 use Koha::Illrequests;
26 my ($c, $args, $cb) = @_;
32 # Create a hash where all keys are embedded values
33 # Enables easy checking
35 if (defined $args->{embed}) {
36 %embed = map { $_ => 1 } @{$args->{embed}};
37 delete $args->{embed};
40 for my $filter_param ( keys %$args ) {
41 my @values = split(/,/, $args->{$filter_param});
42 $filter->{$filter_param} = \@values;
45 my $requests = Koha::Illrequests->search($filter);
47 while (my $request = $requests->next) {
48 my $unblessed = $request->unblessed;
49 # Add the request's id_prefix
50 $unblessed->{id_prefix} = $request->id_prefix;
51 # Augment the request response with patron details
53 if (defined $embed{patron}) {
54 my $patron = $request->patron;
55 $unblessed->{patron} = {
56 firstname => $patron->firstname,
57 surname => $patron->surname,
58 cardnumber => $patron->cardnumber
61 # Augment the request response with metadata details
63 if (defined $embed{metadata}) {
64 $unblessed->{metadata} = $request->metadata;
66 # Augment the request response with status details
68 if (defined $embed{capabilities}) {
69 $unblessed->{capabilities} = $request->capabilities;
71 # Augment the request response with branch details
73 if (defined $embed{branch}) {
74 $unblessed->{branch} = Koha::Libraries->find(
78 push @{$output}, $unblessed
81 return $c->$cb( $output, 200 );