1 package Koha::REST::V1::Acquisitions::Vendors;
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::Booksellers;
28 Koha::REST::V1::Acquisitions::Vendors
36 Controller function that handles listing Koha::Acquisition::Bookseller objects
41 my $c = shift->openapi->valid_input or return;
44 my $vendors_rs = Koha::Acquisition::Booksellers->new;
45 my $vendors = $c->objects->search( $vendors_rs );
52 $c->unhandled_exception($_);
58 Controller function that handles retrieving a single Koha::Acquisition::Bookseller
63 my $c = shift->openapi->valid_input or return;
65 my $vendor = Koha::Acquisition::Booksellers->find( $c->validation->param('vendor_id') );
67 return $c->render( status => 404,
68 openapi => { error => "Vendor not found" } );
74 openapi => $vendor->to_api
78 $c->unhandled_exception($_);
84 Controller function that handles adding a new Koha::Acquisition::Bookseller object
89 my $c = shift->openapi->valid_input or return;
91 my $vendor = Koha::Acquisition::Bookseller->new_from_api( $c->validation->param('body') );
95 $c->res->headers->location($c->req->url->to_string . '/' . $vendor->id );
98 openapi => $vendor->to_api
102 $c->unhandled_exception($_);
108 Controller function that handles updating a Koha::Acquisition::Bookseller object
113 my $c = shift->openapi->valid_input or return;
118 $vendor = Koha::Acquisition::Booksellers->find( $c->validation->param('vendor_id') );
119 $vendor->set_from_api( $c->validation->param('body') );
123 openapi => $vendor->to_api
127 if ( not defined $vendor ) {
130 openapi => { error => "Object not found" }
134 $c->unhandled_exception($_);
142 Controller function that handles deleting a Koha::Acquisition::Bookseller object
147 my $c = shift->openapi->valid_input or return;
150 my $vendor = Koha::Acquisition::Booksellers->find( $c->validation->param('vendor_id') );
155 openapi => { error => "Object not found" }
167 $c->unhandled_exception($_);