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 if ( $_->isa('Koha::Exceptions::Exception') ) {
58 openapi => { error => "Unhandled exception ($_)" }
64 openapi => { error => "Something went wrong, check the logs. ($_)" }
72 Controller function that handles retrieving a single Koha::Acquisition::Order object
77 my $c = shift->openapi->valid_input or return;
79 my $order = Koha::Acquisition::Orders->find( $c->validation->param('order_id') );
84 openapi => { error => "Order not found" }
88 my $embed = $c->stash('koha.embed');
92 openapi => $order->to_api({ embed => $embed })
98 Controller function that handles adding a new Koha::Acquisition::Order object
103 my $c = shift->openapi->valid_input or return;
106 my $order = Koha::Acquisition::Order->new_from_api( $c->validation->param('body') );
107 $order->store->discard_changes;
109 $c->res->headers->location(
110 $c->req->url->to_string . '/' . $order->ordernumber
115 openapi => $order->to_api
119 unless ( blessed $_ && $_->can('rethrow') ) {
124 "Something went wrong, check Koha logs for details."
128 if ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
131 openapi => { error => $_->error, conflict => $_->duplicate_id }
137 openapi => { error => "$_" }
145 Controller function that handles updating a Koha::Acquisition::Order object
150 my $c = shift->openapi->valid_input or return;
152 my $order = Koha::Acquisition::Orders->find( $c->validation->param('order_id') );
157 openapi => { error => "Order not found" }
162 $order->set_from_api( $c->validation->param('body') );
163 $order->store()->discard_changes;
167 openapi => $order->to_api
171 if ( $_->isa('Koha::Exceptions::Exception') ) {
174 openapi => { error => "Unhandled exception ($_)" }
180 openapi => { error => "Something went wrong, check the logs." }
188 Controller function that handles deleting a Koha::Patron object
193 my $c = shift->openapi->valid_input or return;
195 my $order = Koha::Acquisition::Orders->find( $c->validation->param('order_id') );
200 openapi => { error => 'Order not found' }
214 if ( $_->isa('Koha::Exceptions::Exception') ) {
217 openapi => { error => "Unhandled exception ($_)" }
223 openapi => { error => "Something went wrong, check the logs." }