Bugzilla – Attachment 56228 Details for
Bug 17428
REST API: CRUD endpoint for cities
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17428: [REST] Koha::REST::V1::Cities introduced
Bug-17428-REST-KohaRESTV1Cities-introduced.patch (text/plain), 4.54 KB, created by
Josef Moravec
on 2016-10-12 07:51:43 UTC
(
hide
)
Description:
Bug 17428: [REST] Koha::REST::V1::Cities introduced
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2016-10-12 07:51:43 UTC
Size:
4.54 KB
patch
obsolete
>From 391e80ba460b6be21ef6e01429393dec85c41180 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 11 Oct 2016 13:26:39 +0200 >Subject: [PATCH] Bug 17428: [REST] Koha::REST::V1::Cities introduced > >This patch introduces full CRUD for Koha::Cit(ies|y) classes through >the REST api. To test, point your browser to /api/v1/cities to use >HTTPRequester/Postman (or the like). > >And of course, run the unit tests: >- Apply the patches >- Update your minified swagger file: > $ cd kohaclone/ > $ misc/devel/minifySwagger.pl -s api/v1/swagger/swagger.json \ > -d api/v1/swagger/swagger.min.json >- Run: > $ prove t/db_dependent/api/v1/cities.t >=> SUCCESS: Tests should return green, and no warnings. >- Sign off :-D > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >--- > Koha/REST/V1/Cities.pm | 133 +++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 133 insertions(+) > create mode 100644 Koha/REST/V1/Cities.pm > >diff --git a/Koha/REST/V1/Cities.pm b/Koha/REST/V1/Cities.pm >new file mode 100644 >index 0000000..1b04e10 >--- /dev/null >+++ b/Koha/REST/V1/Cities.pm >@@ -0,0 +1,133 @@ >+package Koha::REST::V1::Cities; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Mojo::Base 'Mojolicious::Controller'; >+ >+use C4::Auth qw( haspermission ); >+use Koha::City; >+use Koha::Cities; >+ >+use Try::Tiny; >+ >+sub list { >+ my ( $c, $args, $cb ) = @_; >+ >+ my $cities; >+ >+ return try { >+ $cities = >+ Koha::Cities->search( $c->req->query_params->to_hash )->unblessed; >+ return $c->$cb( $cities, 200 ); >+ } >+ catch { >+ if ( $_->isa('DBIx::Class::Exception') ) { >+ return $c->$cb( { error => $_->{msg} }, 500 ); >+ } >+ else { >+ return $c->$cb( >+ { error => "Something went wrong, check the logs." }, 500 ); >+ } >+ }; >+} >+ >+sub get { >+ my ( $c, $args, $cb ) = @_; >+ >+ my $city = Koha::Cities->find( $args->{cityid} ); >+ unless ($city) { >+ return $c->$cb( { error => "City not found" }, 404 ); >+ } >+ >+ return $c->$cb( $city->unblessed, 200 ); >+} >+ >+sub add { >+ my ( $c, $args, $cb ) = @_; >+ >+ my $city = Koha::City->new( $c->req->json ); >+ >+ return try { >+ $city->store; >+ return $c->$cb( $city->unblessed, 200 ); >+ } >+ catch { >+ if ( $_->isa('DBIx::Class::Exception') ) { >+ return $c->$cb( { error => $_->msg }, 500 ); >+ } >+ else { >+ return $c->$cb( >+ { error => "Something went wrong, check the logs." }, 500 ); >+ } >+ }; >+} >+ >+sub update { >+ my ( $c, $args, $cb ) = @_; >+ >+ my $city; >+ >+ return try { >+ $city = Koha::Cities->find( $args->{cityid} ); >+ while ( my ( $k, $v ) = each %{ $c->req->json } ) { >+ $city->$k($v); >+ } >+ $city->store; >+ return $c->$cb( $city->unblessed, 200 ); >+ } >+ catch { >+ if ( not defined $city ) { >+ return $c->$cb( { error => "Object not found" }, 404 ); >+ } >+ elsif ( $_->isa('Koha::Exceptions::Object') ) { >+ return $c->$cb( { error => $_->message }, 500 ); >+ } >+ else { >+ return $c->$cb( >+ { error => "Something went wrong, check the logs." }, 500 ); >+ } >+ }; >+ >+} >+ >+sub delete { >+ my ( $c, $args, $cb ) = @_; >+ >+ my $city; >+ >+ return try { >+ $city = Koha::Cities->find( $args->{cityid} ); >+ $city->delete; >+ return $c->$cb( "", 200 ); >+ } >+ catch { >+ if ( not defined $city ) { >+ return $c->$cb( { error => "Object not found" }, 404 ); >+ } >+ elsif ( $_->isa('DBIx::Class::Exception') ) { >+ return $c->$cb( { error => $_->msg }, 500 ); >+ } >+ else { >+ return $c->$cb( >+ { error => "Something went wrong, check the logs." }, 500 ); >+ } >+ }; >+ >+} >+ >+1; >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17428
:
56189
|
56190
|
56191
|
56226
|
56227
|
56228
|
56261
|
56314
|
56501
|
56544
|
56545
|
56548
|
56553
|
56554
|
56555
|
56556
|
56557
|
56558
|
56559
|
56724
|
56741
|
56800
|
56801
|
56802
|
56803
|
56804
|
56807
|
56808
|
56809
|
56810
|
56811
|
56812