From def667f7fc1b64171bec937861e34c5a94ead0d7 Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Mon, 1 Apr 2019 15:08:26 +0000 Subject: [PATCH] Bug 22615: Add /ill_backends endpoint Signed-off-by: Andrew Isherwood Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize --- Koha/REST/V1/Illbackends.pm | 54 +++++++++++++++++++ api/v1/swagger/definitions.json | 3 ++ api/v1/swagger/definitions/ill_backend.json | 13 +++++ api/v1/swagger/definitions/ill_backends.json | 6 +++ api/v1/swagger/paths.json | 3 ++ api/v1/swagger/paths/ill_backends.json | 56 ++++++++++++++++++++ 6 files changed, 135 insertions(+) create mode 100644 Koha/REST/V1/Illbackends.pm create mode 100644 api/v1/swagger/definitions/ill_backend.json create mode 100644 api/v1/swagger/definitions/ill_backends.json create mode 100644 api/v1/swagger/paths/ill_backends.json diff --git a/Koha/REST/V1/Illbackends.pm b/Koha/REST/V1/Illbackends.pm new file mode 100644 index 0000000000..01cdd9e5e0 --- /dev/null +++ b/Koha/REST/V1/Illbackends.pm @@ -0,0 +1,54 @@ +package Koha::REST::V1::Illbackends; + +# 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 Koha::Illrequest::Config; +use Koha::Illrequests; + +=head1 NAME + +Koha::REST::V1::Illbackends + +=head2 Operations + +=head3 list + +Return a list of available ILL backends and its capabilities + +=cut + +sub list { + my $c = shift->openapi->valid_input; + + my $config = Koha::Illrequest::Config->new; + my $backends = $config->available_backends; + + my @data; + foreach $b ( @$backends ) { + my $backend = Koha::Illrequest->new->load_backend( $b ); + push @data, { + ill_backend_id => $b, + capabilities => $backend->capabilities, + }; + } + return $c->render( status => 200, openapi => \@data ); +} + +1; diff --git a/api/v1/swagger/definitions.json b/api/v1/swagger/definitions.json index a27fa0de22..26765383e7 100644 --- a/api/v1/swagger/definitions.json +++ b/api/v1/swagger/definitions.json @@ -32,6 +32,9 @@ "holds": { "$ref": "definitions/holds.json" }, + "ill_backends": { + "$ref": "definitions/ill_backends.json" + }, "library": { "$ref": "definitions/library.json" }, diff --git a/api/v1/swagger/definitions/ill_backend.json b/api/v1/swagger/definitions/ill_backend.json new file mode 100644 index 0000000000..f67dc47ea2 --- /dev/null +++ b/api/v1/swagger/definitions/ill_backend.json @@ -0,0 +1,13 @@ +{ + "type": "object", + "properties": { + "ill_backend_id": { + "type": "string", + "description": "Internal ILL backend identifier" + }, + "capabilities": { + "type": "object", + "description": "List of capabilities" + } + } +} diff --git a/api/v1/swagger/definitions/ill_backends.json b/api/v1/swagger/definitions/ill_backends.json new file mode 100644 index 0000000000..fc68c500e4 --- /dev/null +++ b/api/v1/swagger/definitions/ill_backends.json @@ -0,0 +1,6 @@ +{ + "type": "array", + "items": { + "$ref": "ill_backend.json" + } +} diff --git a/api/v1/swagger/paths.json b/api/v1/swagger/paths.json index ed9ed0627c..c4a16f8a6f 100644 --- a/api/v1/swagger/paths.json +++ b/api/v1/swagger/paths.json @@ -83,6 +83,9 @@ "/patrons/{patron_id}/password": { "$ref": "paths/patrons_password.json#/~1patrons~1{patron_id}~1password" }, + "/ill_backends": { + "$ref": "paths/ill_backends.json#/~1ill_backends" + }, "/illrequests": { "$ref": "paths/illrequests.json#/~1illrequests" }, diff --git a/api/v1/swagger/paths/ill_backends.json b/api/v1/swagger/paths/ill_backends.json new file mode 100644 index 0000000000..a14c3d651e --- /dev/null +++ b/api/v1/swagger/paths/ill_backends.json @@ -0,0 +1,56 @@ +{ + "/ill_backends": { + "get": { + "x-mojo-to": "Illbackends#list", + "operationId": "listIllbackends", + "tags": ["illbackends"], + "parameters": [], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "A list of ILL backends", + "schema": { + "$ref": "../definitions.json#/ill_backends" + } + }, + "401": { + "description": "Authentication required", + "schema": { + "$ref": "../definitions.json#/error" + } + }, + "403": { + "description": "Access forbidden", + "schema": { + "$ref": "../definitions.json#/error" + } + }, + "404": { + "description": "ILL backends not found", + "schema": { + "$ref": "../definitions.json#/error" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "$ref": "../definitions.json#/error" + } + }, + "503": { + "description": "Under maintenance", + "schema": { + "$ref": "../definitions.json#/error" + } + } + }, + "x-koha-authorization": { + "permissions": { + "ill": "1" + } + } + } + } +} -- 2.39.5