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';
35 my $c = shift->openapi->valid_input or return;
38 my $cities_set = Koha::Cities->new;
39 my $cities = $c->objects->search( $cities_set );
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."} );
60 my $c = shift->openapi->valid_input or return;
62 my $city = Koha::Cities->find( $c->validation->param('city_id') );
64 return $c->render( status => 404,
65 openapi => { error => "City not found" } );
68 return $c->render( status => 200, openapi => $city->to_api );
76 my $c = shift->openapi->valid_input or return;
79 my $city = Koha::City->new_from_api( $c->validation->param('body') );
81 $c->res->headers->location( $c->req->url->to_string . '/' . $city->cityid );
84 openapi => $city->to_api
88 if ( $_->isa('DBIx::Class::Exception') ) {
91 openapi => { error => $_->{msg} }
97 openapi => { error => "Something went wrong, check the logs." }
108 my $c = shift->openapi->valid_input or return;
110 my $city = Koha::Cities->find( $c->validation->param('city_id') );
112 if ( not defined $city ) {
113 return $c->render( status => 404,
114 openapi => { error => "Object not found" } );
118 $city->set_from_api( $c->validation->param('body') );
120 return $c->render( status => 200, openapi => $city->to_api );
123 if ( $_->isa('Koha::Exceptions::Object') ) {
124 return $c->render( status => 500,
125 openapi => { error => $_->message } );
128 return $c->render( status => 500,
129 openapi => { error => "Something went wrong, check the logs."} );
139 my $c = shift->openapi->valid_input or return;
141 my $city = Koha::Cities->find( $c->validation->param('city_id') );
142 if ( not defined $city ) {
143 return $c->render( status => 404,
144 openapi => { error => "Object not found" } );
149 return $c->render( status => 200, openapi => "" );
152 if ( $_->isa('DBIx::Class::Exception') ) {
153 return $c->render( status => 500,
154 openapi => { error => $_->{msg} } );
157 return $c->render( status => 500,
158 openapi => { error => "Something went wrong, check the logs."} );