1 package Koha::REST::V1::Quotes;
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';
35 my $c = shift->openapi->valid_input or return;
38 my $quotes_set = Koha::Quotes->new;
39 my $quotes = $c->objects->search( $quotes_set );
40 return $c->render( status => 200, openapi => $quotes );
43 $c->unhandled_exception($_);
53 my $c = shift->openapi->valid_input or return;
56 my $quote = Koha::Quotes->find( $c->validation->param('quote_id') );
58 return $c->render( status => 404,
59 openapi => { error => "quote not found" } );
62 return $c->render( status => 200, openapi => $quote->to_api );
65 $c->unhandled_exception($_);
74 my $c = shift->openapi->valid_input or return;
77 my $quote = Koha::Quote->new_from_api( $c->validation->param('body') );
79 $c->res->headers->location( $c->req->url->to_string . '/' . $quote->id );
82 openapi => $quote->to_api
86 $c->unhandled_exception($_);
95 my $c = shift->openapi->valid_input or return;
97 my $quote = Koha::Quotes->find( $c->validation->param('quote_id') );
99 if ( not defined $quote ) {
100 return $c->render( status => 404,
101 openapi => { error => "Object not found" } );
105 $quote->set_from_api( $c->validation->param('body') );
107 return $c->render( status => 200, openapi => $quote->to_api );
110 $c->unhandled_exception($_);
119 my $c = shift->openapi->valid_input or return;
121 my $quote = Koha::Quotes->find( $c->validation->param('quote_id') );
122 if ( not defined $quote ) {
123 return $c->render( status => 404,
124 openapi => { error => "Object not found" } );
135 $c->unhandled_exception($_);