1 package Koha::REST::V1::Patrons::Holds;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Mojo::Base 'Mojolicious::Controller';
26 Koha::REST::V1::Patrons::Holds
34 Controller function that handles listing Koha::Hold objects for the requested patron
39 my $c = shift->openapi->valid_input or return;
41 my $patron = Koha::Patrons->find( $c->param('patron_id') );
47 error => 'Patron not found'
52 my $old = $c->param('old');
53 $c->req->params->remove('old');
61 my $holds = $c->objects->search( $holds_set );
62 return $c->render( status => 200, openapi => $holds );
64 $c->unhandled_exception($_);
71 Controller function that handles cancelling a hold for the requested patron. Returns
72 a I<204> if cancelling took place, and I<202> if a cancellation request is recorded
78 my $c = shift->openapi->valid_input or return;
81 my $hold = $c->objects->find_rs( Koha::Holds->new, $c->param('hold_id') );
83 unless ( $hold and $c->param('patron_id') == $hold->borrowernumber ) {
86 openapi => { error => 'Object not found' }
90 if ( $hold->is_cancelable_from_opac ) {
96 } elsif ( $hold->is_waiting and $hold->cancellation_requestable_from_opac ) {
97 $hold->add_cancellation_request;
105 openapi => { error => 'Cancellation forbidden' }
109 $c->unhandled_exception($_);