From ae1e0a3a8e5100c4608102a0d40fa8045b70c991 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 7 Oct 2015 14:49:17 +0000 Subject: [PATCH 2/4] Bug 15126: x-mojo-controller deprecation Remove the use of soon to be deprecated x-mojo-controller from our specification and replace with the recommended operationId format. Signed-off-by: Benjamin Rokseth Signed-off-by: Kyle M Hall --- Koha/REST/V1/Patron.pm | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ Koha/REST/V1/Patrons.pm | 58 ------------------------------------------------- api/v1/swagger.json | 2 -- 3 files changed, 58 insertions(+), 60 deletions(-) create mode 100644 Koha/REST/V1/Patron.pm delete mode 100644 Koha/REST/V1/Patrons.pm diff --git a/Koha/REST/V1/Patron.pm b/Koha/REST/V1/Patron.pm new file mode 100644 index 0000000..2851308 --- /dev/null +++ b/Koha/REST/V1/Patron.pm @@ -0,0 +1,58 @@ +package Koha::REST::V1::Patron; + +# 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::Patrons; + +sub list { + my ($c, $args, $cb) = @_; + + my $user = $c->stash('koha.user'); + unless ($user && haspermission($user->userid, {borrowers => 1})) { + return $c->$cb({error => "You don't have the required permission"}, 403); + } + + my $patrons = Koha::Patrons->search; + + $c->$cb($patrons->unblessed, 200); +} + +sub get { + my ($c, $args, $cb) = @_; + + my $user = $c->stash('koha.user'); + + unless ( $user + && ( $user->borrowernumber == $args->{borrowernumber} + || haspermission($user->userid, {borrowers => 1}) ) ) + { + return $c->$cb({error => "You don't have the required permission"}, 403); + } + + my $patron = Koha::Patrons->find($args->{borrowernumber}); + unless ($patron) { + return $c->$cb({error => "Patron not found"}, 404); + } + + return $c->$cb($patron->unblessed, 200); +} + +1; diff --git a/Koha/REST/V1/Patrons.pm b/Koha/REST/V1/Patrons.pm deleted file mode 100644 index 426145f..0000000 --- a/Koha/REST/V1/Patrons.pm +++ /dev/null @@ -1,58 +0,0 @@ -package Koha::REST::V1::Patrons; - -# 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::Patrons; - -sub list_patrons { - my ($c, $args, $cb) = @_; - - my $user = $c->stash('koha.user'); - unless ($user && haspermission($user->userid, {borrowers => 1})) { - return $c->$cb({error => "You don't have the required permission"}, 403); - } - - my $patrons = Koha::Patrons->search; - - $c->$cb($patrons->unblessed, 200); -} - -sub get_patron { - my ($c, $args, $cb) = @_; - - my $user = $c->stash('koha.user'); - - unless ( $user - && ( $user->borrowernumber == $args->{borrowernumber} - || haspermission($user->userid, {borrowers => 1}) ) ) - { - return $c->$cb({error => "You don't have the required permission"}, 403); - } - - my $patron = Koha::Patrons->find($args->{borrowernumber}); - unless ($patron) { - return $c->$cb({error => "Patron not found"}, 404); - } - - return $c->$cb($patron->unblessed, 200); -} - -1; diff --git a/api/v1/swagger.json b/api/v1/swagger.json index 8f32781..e821c44 100644 --- a/api/v1/swagger.json +++ b/api/v1/swagger.json @@ -16,7 +16,6 @@ "paths": { "/patrons": { "get": { - "x-mojo-controller": "Koha::REST::V1::Patrons", "operationId": "listPatrons", "tags": ["patrons"], "produces": [ @@ -43,7 +42,6 @@ }, "/patrons/{borrowernumber}": { "get": { - "x-mojo-controller": "Koha::REST::V1::Patrons", "operationId": "getPatron", "tags": ["patrons"], "parameters": [ -- 2.1.4