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
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';
23 use Koha::Illrequests;
24 use Koha::Illrequestattributes;
28 use Koha::DateUtils qw( format_sqldatetime );
30 use Scalar::Util qw( blessed );
31 use Try::Tiny qw( catch try );
35 Koha::REST::V1::Illrequests
41 Controller function that handles listing Koha::Illrequest objects
46 my $c = shift->openapi->valid_input or return;
50 my $reqs = $c->objects->search(Koha::Illrequests->new->filter_by_visible);
57 $c->unhandled_exception($_);
63 Adds a new ILL request
68 my $c = shift->openapi->valid_input or return;
72 Koha::Database->new->schema->txn_do(
75 my $body = $c->validation->param('body');
76 $body->{backend} = delete $body->{ill_backend_id};
77 $body->{borrowernumber} = delete $body->{patron_id};
78 $body->{branchcode} = delete $body->{library_id};
80 my $request = Koha::Illrequest->new->load_backend( $body->{backend} );
82 my $create_api = $request->_backend->capabilities('create_api');
88 errors => [ 'This backend does not allow request creation via API' ]
93 my $create_result = &{$create_api}($body, $request);
94 my $new_id = $create_result->illrequest_id;
96 my @new_req = Koha::Illrequests->search({
97 illrequest_id => $new_id
100 $c->res->headers->location($c->req->url->to_string . '/' . $new_req[0]->illrequest_id);
103 openapi => $new_req[0]->to_api
110 my $to_api_mapping = Koha::Illrequest->new->to_api_mapping;
113 if ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
116 openapi => { error => $_->error, conflict => $_->duplicate_id }
119 elsif ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
124 . $to_api_mapping->{ $_->broken_fk }
129 elsif ( $_->isa('Koha::Exceptions::BadParameter') ) {
134 . $to_api_mapping->{ $_->parameter }
141 $c->unhandled_exception($_);