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 under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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." }