1 package Koha::REST::V1::Clubs::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';
32 use Scalar::Util qw(blessed);
34 use List::Util 'shuffle';
42 Method that handles adding a new Koha::Hold object
47 my $c = shift->openapi->valid_input or return;
50 my $body = $c->validation->param('body');
51 my $club_id = $c->validation->param('club_id');
55 my $biblio_id = $body->{biblio_id};
56 my $pickup_library_id = $body->{pickup_library_id};
57 my $item_id = $body->{item_id};
58 my $item_type = $body->{item_type};
59 my $expiration_date = $body->{expiration_date};
60 my $notes = $body->{notes};
61 my $default_patron_home = $body->{default_patron_home};
63 if ( $item_id and $biblio_id ) {
65 # check they are consistent
66 unless ( Koha::Items->search( { itemnumber => $item_id, biblionumber => $biblio_id } )
71 openapi => { error => "Item $item_id doesn't belong to biblio $biblio_id" }
75 $biblio = Koha::Biblios->find($biblio_id);
79 my $item = Koha::Items->find($item_id);
84 openapi => { error => "Item not found" }
88 $biblio = $item->biblio;
92 $biblio = Koha::Biblios->find($biblio_id);
97 openapi => { error => "At least one of biblio_id, item_id should be given" }
104 openapi => { error => "Biblio not found" }
108 # AddReserve expects date to be in syspref format
109 if ($expiration_date) {
110 $expiration_date = output_pref( dt_from_string( $expiration_date, 'rfc3339' ) );
113 my $club_hold = Koha::Club::Hold::add(
116 biblio_id => $biblio->biblionumber,
118 pickup_library_id => $pickup_library_id,
119 expiration_date => $expiration_date,
121 item_type => $item_type,
122 default_patron_home => $default_patron_home
128 openapi => $club_hold->to_api
133 if ($_->isa('Koha::Exceptions::ClubHold::NoPatrons')) {
136 openapi => { error => $_->description }
141 $c->unhandled_exception($_);