1 package Koha
::REST
::V1
::Cities
;
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';
28 my $c = shift->openapi->valid_input or return;
32 my $args = $c->req->params->to_hash;
34 for my $filter_param ( keys %$args ) {
35 $filter->{$filter_param} = { LIKE
=> $args->{$filter_param} . "%" };
39 $cities = Koha
::Cities
->search($filter);
40 return $c->render( status
=> 200, openapi
=> $cities );
43 if ( $_->isa('DBIx::Class::Exception') ) {
44 return $c->render( status
=> 500,
45 openapi
=> { error
=> $_->{msg
} } );
48 return $c->render( status
=> 500,
49 openapi
=> { error
=> "Something went wrong, check the logs."} );
56 my $c = shift->openapi->valid_input or return;
58 my $city = Koha
::Cities
->find( $c->validation->param('cityid') );
60 return $c->render( status
=> 404,
61 openapi
=> { error
=> "City not found" } );
64 return $c->render( status
=> 200, openapi
=> $city );
68 my $c = shift->openapi->valid_input or return;
70 my $city = Koha
::City
->new( $c->validation->param('body') );
74 return $c->render( status
=> 200, openapi
=> $city );
77 if ( $_->isa('DBIx::Class::Exception') ) {
78 return $c->render( status
=> 500,
79 openapi
=> { error
=> $_->{msg
} } );
82 return $c->render( status
=> 500,
83 openapi
=> { error
=> "Something went wrong, check the logs."} );
89 my $c = shift->openapi->valid_input or return;
94 $city = Koha
::Cities
->find( $c->validation->param('cityid') );
95 my $params = $c->req->json;
96 $city->set( $params );
98 return $c->render( status
=> 200, openapi
=> $city );
101 if ( not defined $city ) {
102 return $c->render( status
=> 404,
103 openapi
=> { error
=> "Object not found" } );
105 elsif ( $_->isa('Koha::Exceptions::Object') ) {
106 return $c->render( status
=> 500,
107 openapi
=> { error
=> $_->message } );
110 return $c->render( status
=> 500,
111 openapi
=> { error
=> "Something went wrong, check the logs."} );
118 my $c = shift->openapi->valid_input or return;
123 $city = Koha
::Cities
->find( $c->validation->param('cityid') );
125 return $c->render( status
=> 200, openapi
=> "" );
128 if ( not defined $city ) {
129 return $c->render( status
=> 404,
130 openapi
=> { error
=> "Object not found" } );
132 elsif ( $_->isa('DBIx::Class::Exception') ) {
133 return $c->render( status
=> 500,
134 openapi
=> { error
=> $_->{msg
} } );
137 return $c->render( status
=> 500,
138 openapi
=> { error
=> "Something went wrong, check the logs."} );