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 if ( $_->isa('DBIx::Class::Exception') ) {
53 return $c->render( status => 500,
54 openapi => { error => $_->{msg} } );
57 return $c->render( status => 500,
58 openapi => { error => "Something went wrong, check the logs." } );
65 Controller function that handles retrieving a single Koha::Acquisition::Bookseller
70 my $c = shift->openapi->valid_input or return;
72 my $vendor = Koha::Acquisition::Booksellers->find( $c->validation->param('vendor_id') );
74 return $c->render( status => 404,
75 openapi => { error => "Vendor not found" } );
80 openapi => $vendor->to_api
86 Controller function that handles adding a new Koha::Acquisition::Bookseller object
91 my $c = shift->openapi->valid_input or return;
93 my $vendor = Koha::Acquisition::Bookseller->new_from_api( $c->validation->param('body') );
97 $c->res->headers->location($c->req->url->to_string . '/' . $vendor->id );
100 openapi => $vendor->to_api
104 if ( $_->isa('DBIx::Class::Exception') ) {
105 return $c->render( status => 500,
106 openapi => { error => $_->msg } );
109 return $c->render( status => 500,
110 openapi => { error => "Something went wrong, check the logs." } );
117 Controller function that handles updating a Koha::Acquisition::Bookseller object
122 my $c = shift->openapi->valid_input or return;
127 $vendor = Koha::Acquisition::Booksellers->find( $c->validation->param('vendor_id') );
128 $vendor->set_from_api( $c->validation->param('body') );
132 openapi => $vendor->to_api
136 if ( not defined $vendor ) {
137 return $c->render( status => 404,
138 openapi => { error => "Object not found" } );
140 elsif ( $_->isa('Koha::Exceptions::Object') ) {
141 return $c->render( status => 500,
142 openapi => { error => $_->message } );
145 return $c->render( status => 500,
146 openapi => { error => "Something went wrong, check the logs." } );
154 Controller function that handles deleting a Koha::Acquisition::Bookseller object
159 my $c = shift->openapi->valid_input or return;
164 $vendor = Koha::Acquisition::Booksellers->find( $c->validation->param('vendor_id') );
166 return $c->render( status => 200,
170 if ( not defined $vendor ) {
171 return $c->render( status => 404,
172 openapi => { error => "Object not found" } );
174 elsif ( $_->isa('DBIx::Class::Exception') ) {
175 return $c->render( status => 500,
176 openapi => { error => $_->msg } );
179 return $c->render( status => 500,
180 openapi => { error => "Something went wrong, check the logs." } );