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';
22 use C4::Auth qw( haspermission );
29 my ( $c, $args, $cb ) = @_;
35 for my $filter_param ( keys %$args ) {
36 $filter->{$filter_param} = { LIKE => $args->{$filter_param} . "%" };
40 $cities = Koha::Cities->search($filter)->unblessed;
41 return $c->$cb( $cities, 200 );
44 if ( $_->isa('DBIx::Class::Exception') ) {
45 return $c->$cb( { error => $_->{msg} }, 500 );
49 { error => "Something went wrong, check the logs." }, 500 );
55 my ( $c, $args, $cb ) = @_;
57 my $city = Koha::Cities->find( $args->{cityid} );
59 return $c->$cb( { error => "City not found" }, 404 );
62 return $c->$cb( $city->unblessed, 200 );
66 my ( $c, $args, $cb ) = @_;
68 my $city = Koha::City->new( $args->{body} );
72 return $c->$cb( $city->unblessed, 200 );
75 if ( $_->isa('DBIx::Class::Exception') ) {
76 return $c->$cb( { error => $_->msg }, 500 );
80 { error => "Something went wrong, check the logs." }, 500 );
86 my ( $c, $args, $cb ) = @_;
91 $city = Koha::Cities->find( $args->{cityid} );
92 $city->set( $args->{body} );
94 return $c->$cb( $city->unblessed, 200 );
97 if ( not defined $city ) {
98 return $c->$cb( { error => "Object not found" }, 404 );
100 elsif ( $_->isa('Koha::Exceptions::Object') ) {
101 return $c->$cb( { error => $_->message }, 500 );
105 { error => "Something went wrong, check the logs." }, 500 );
112 my ( $c, $args, $cb ) = @_;
117 $city = Koha::Cities->find( $args->{cityid} );
119 return $c->$cb( "", 200 );
122 if ( not defined $city ) {
123 return $c->$cb( { error => "Object not found" }, 404 );
125 elsif ( $_->isa('DBIx::Class::Exception') ) {
126 return $c->$cb( { error => $_->msg }, 500 );
130 { error => "Something went wrong, check the logs." }, 500 );