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, $args, $cb ) = @_;
34 for my $filter_param ( keys %$args ) {
35 $filter->{$filter_param} = { LIKE => $args->{$filter_param} . "%" };
39 $cities = Koha::Cities->search($filter);
40 return $c->$cb( $cities, 200 );
43 if ( $_->isa('DBIx::Class::Exception') ) {
44 return $c->$cb( { error => $_->{msg} }, 500 );
48 { error => "Something went wrong, check the logs." }, 500 );
54 my ( $c, $args, $cb ) = @_;
56 my $city = Koha::Cities->find( $args->{cityid} );
58 return $c->$cb( { error => "City not found" }, 404 );
61 return $c->$cb( $city, 200 );
65 my ( $c, $args, $cb ) = @_;
67 my $city = Koha::City->new( $args->{body} );
71 return $c->$cb( $city, 200 );
74 if ( $_->isa('DBIx::Class::Exception') ) {
75 return $c->$cb( { error => $_->msg }, 500 );
79 { error => "Something went wrong, check the logs." }, 500 );
85 my ( $c, $args, $cb ) = @_;
90 $city = Koha::Cities->find( $args->{cityid} );
91 $city->set( $args->{body} );
93 return $c->$cb( $city, 200 );
96 if ( not defined $city ) {
97 return $c->$cb( { error => "Object not found" }, 404 );
99 elsif ( $_->isa('Koha::Exceptions::Object') ) {
100 return $c->$cb( { error => $_->message }, 500 );
104 { error => "Something went wrong, check the logs." }, 500 );
111 my ( $c, $args, $cb ) = @_;
116 $city = Koha::Cities->find( $args->{cityid} );
118 return $c->$cb( "", 200 );
121 if ( not defined $city ) {
122 return $c->$cb( { error => "Object not found" }, 404 );
124 elsif ( $_->isa('DBIx::Class::Exception') ) {
125 return $c->$cb( { error => $_->msg }, 500 );
129 { error => "Something went wrong, check the logs." }, 500 );