From 612877b8c5dc0d50fbb7045508b33dcc5903a3ed Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Sat, 1 Oct 2016 18:09:33 +0000 Subject: [PATCH] Bug 17390 - Add REST API endpoint for Authorised Values It would be good and useful to at least be able to get the list of authorised values from Koha. The ability to create, update and delete could come later. --- Koha/REST/V1/AuthorisedValue.pm | 48 ++++++++++++++++++++++++ api/v1/swagger/definitions.json | 6 +++ api/v1/swagger/definitions/authorised_value.json | 25 ++++++++++++ api/v1/swagger/paths.json | 3 ++ api/v1/swagger/paths/authorised_values.json | 28 ++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 Koha/REST/V1/AuthorisedValue.pm create mode 100644 api/v1/swagger/definitions/authorised_value.json create mode 100644 api/v1/swagger/paths/authorised_values.json diff --git a/Koha/REST/V1/AuthorisedValue.pm b/Koha/REST/V1/AuthorisedValue.pm new file mode 100644 index 0000000000..141b6d5d76 --- /dev/null +++ b/Koha/REST/V1/AuthorisedValue.pm @@ -0,0 +1,48 @@ +package Koha::REST::V1::AuthorisedValue; + +# 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::AuthorizedValues; + +BEGIN { + warn "TEST"; +} + +sub list { + my ( $c, $args, $cb ) = @_; + + my $user = $c->stash('koha.user'); + unless ( $user && haspermission( $user->userid, { catalogue => 1 } ) ) { + return $c->$cb( + { + error => "You don't have the required permission" + }, + 403 + ); + } + + my $params = $c->req->params->to_hash; + my $av = Koha::Account::AuthorisedValues->search($params); + + return $c->$cb( $av->unblessed, 200 ); +} + +1; diff --git a/api/v1/swagger/definitions.json b/api/v1/swagger/definitions.json index e3001b5e60..fa21cd897b 100644 --- a/api/v1/swagger/definitions.json +++ b/api/v1/swagger/definitions.json @@ -2,6 +2,9 @@ "account_line": { "$ref": "definitions/account_line.json" }, + "authorised_value": { + "$ref": "definitions/authorised_value.json" + }, "city": { "$ref": "definitions/city.json" }, @@ -40,5 +43,8 @@ }, "fund": { "$ref": "definitions/fund.json" + }, + "error": { + "$ref": "definitions/error.json" } } diff --git a/api/v1/swagger/definitions/authorised_value.json b/api/v1/swagger/definitions/authorised_value.json new file mode 100644 index 0000000000..41e4b0eb68 --- /dev/null +++ b/api/v1/swagger/definitions/authorised_value.json @@ -0,0 +1,25 @@ +{ + "type": "object", + "properties": { + "id": { + "description": "The internal id for this authorised value" + }, + "category": { + "description": "The category of this authorised value" + }, + "authorised_value": { + "description": "The code for this authorised value" + }, + "lib": { + "description": "The staff interface description for this authorised value" + }, + "lib_opac": { + "type": ["string", "null"], + "description": "The public interface description of this authorised value, if set" + }, + "imageurl": { + "type": ["string", "null"], + "description": "The url of the image associated with this authorised value, if any" + } + } +} diff --git a/api/v1/swagger/paths.json b/api/v1/swagger/paths.json index 5d544f5c5e..d7eedb52bb 100644 --- a/api/v1/swagger/paths.json +++ b/api/v1/swagger/paths.json @@ -11,6 +11,9 @@ "/acquisitions/funds": { "$ref": "paths/acquisitions_funds.json#/~1acquisitions~1funds" }, + "/authorised_values": { + "$ref": "paths/authorised_values.json#/~1authorised_values" + }, "/checkouts": { "$ref": "paths/checkouts.json#/~1checkouts" }, diff --git a/api/v1/swagger/paths/authorised_values.json b/api/v1/swagger/paths/authorised_values.json new file mode 100644 index 0000000000..084c58bbb8 --- /dev/null +++ b/api/v1/swagger/paths/authorised_values.json @@ -0,0 +1,28 @@ +{ + "/authorised_values": { + "get": { + "operationId": "listAuthorisedValues", + "tags": ["authorised", "values"], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "A list of authorised values", + "schema": { + "type": "array", + "items": { + "$ref": "../definitions.json#/authorised_value" + } + } + }, + "403": { + "description": "Access forbidden", + "schema": { + "$ref": "../definitions.json#/error" + } + } + } + } + } +} -- 2.11.0