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
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';
24 use Try::Tiny qw( catch try );
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 $c->unhandled_exception($_);
53 my $c = shift->openapi->valid_input or return;
56 my $city = Koha::Cities->find( $c->validation->param('city_id') );
58 return $c->render( status => 404,
59 openapi => { error => "City not found" } );
62 return $c->render( status => 200, openapi => $city->to_api );
65 $c->unhandled_exception($_);
74 my $c = shift->openapi->valid_input or return;
77 my $city = Koha::City->new_from_api( $c->validation->param('body') );
79 $c->res->headers->location( $c->req->url->to_string . '/' . $city->cityid );
82 openapi => $city->to_api
86 $c->unhandled_exception($_);
95 my $c = shift->openapi->valid_input or return;
97 my $city = Koha::Cities->find( $c->validation->param('city_id') );
99 if ( not defined $city ) {
100 return $c->render( status => 404,
101 openapi => { error => "Object not found" } );
105 $city->set_from_api( $c->validation->param('body') );
107 return $c->render( status => 200, openapi => $city->to_api );
110 $c->unhandled_exception($_);
119 my $c = shift->openapi->valid_input or return;
121 my $city = Koha::Cities->find( $c->validation->param('city_id') );
122 if ( not defined $city ) {
123 return $c->render( status => 404,
124 openapi => { error => "Object not found" } );
135 $c->unhandled_exception($_);