1 package Koha::REST::V1::Acquisitions::Orders;
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';
22 use Koha::Acquisition::Orders;
25 use Scalar::Util qw( blessed );
30 Koha::REST::V1::Acquisitions::Orders
38 Controller function that handles listing Koha::Acquisition::Order objects
44 my $c = shift->openapi->valid_input or return;
47 my $orders = $c->objects->search( Koha::Acquisition::Orders->new );
55 $c->unhandled_exception($_);
61 Controller function that handles retrieving a single Koha::Acquisition::Order object
66 my $c = shift->openapi->valid_input or return;
68 my $order = Koha::Acquisition::Orders->find( $c->validation->param('order_id') );
73 openapi => { error => "Order not found" }
78 my $embed = $c->stash('koha.embed');
82 openapi => $order->to_api({ embed => $embed })
86 $c->unhandled_exception($_);
92 Controller function that handles adding a new Koha::Acquisition::Order object
97 my $c = shift->openapi->valid_input or return;
100 my $order = Koha::Acquisition::Order->new_from_api( $c->validation->param('body') );
101 $order->store->discard_changes;
103 $c->res->headers->location(
104 $c->req->url->to_string . '/' . $order->ordernumber
109 openapi => $order->to_api
113 if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
116 openapi => { error => $_->error, conflict => $_->duplicate_id }
120 $c->unhandled_exception($_);
126 Controller function that handles updating a Koha::Acquisition::Order object
131 my $c = shift->openapi->valid_input or return;
133 my $order = Koha::Acquisition::Orders->find( $c->validation->param('order_id') );
138 openapi => { error => "Order not found" }
143 $order->set_from_api( $c->validation->param('body') );
144 $order->store()->discard_changes;
148 openapi => $order->to_api
152 $c->unhandled_exception($_);
158 Controller function that handles deleting a Koha::Patron object
163 my $c = shift->openapi->valid_input or return;
165 my $order = Koha::Acquisition::Orders->find( $c->validation->param('order_id') );
170 openapi => { error => 'Order not found' }
184 $c->unhandled_exception($_);