Bug 32997: Add REST API endpoint to list authorised values for multiple given categories

This patch adds /api/v1/authorised_value_categories endpoint that
retrieves authorised value categories for the given names and their
authorised values if x-koha-embed: authorised_values is also given.

To test:
Apply patch
curl -u koha:koha --request GET \"http://localhost:8081/api/v1/authorised_value_categories?q=%7B%22me.category_name%22%3A%5B%22LOC%22%2C%22YES_NO%22%5D%7D\" --header \"x-koha-embed:authorised_values\"

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Pedro Amorim 2023-02-20 16:17:41 +00:00 committed by Tomas Cohen Arazi
parent 23ab22b0da
commit bbc0e8fe32
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
5 changed files with 146 additions and 0 deletions

View File

@ -33,6 +33,19 @@ Koha::AuthorisedValueCategory - Koha AuthorisedValueCategory Object class
=cut
=head3 authorised_values
Returns the authorised values for this authorised value category
=cut
sub authorised_values {
my ( $self ) = @_;
my $authorised_values_rs = $self->_result->authorised_values;
return Koha::AuthorisedValues->_new_from_dbic($authorised_values_rs);
}
=head3 delete
Overridden delete method to prevent system default deletions

View File

@ -0,0 +1,49 @@
package Koha::REST::V1::AuthorisedValueCategories;
# 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, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Mojo::Base 'Mojolicious::Controller';
use Koha::AuthorisedValues;
use Koha::AuthorisedValueCategories;
use Try::Tiny;
=head1 API
=head2 Methods
=head3 list
=cut
sub list {
my $c = shift->openapi->valid_input or return;
return try {
my $authorised_value_categories_set = Koha::AuthorisedValueCategories->new;
my $authorised_value_categories = $c->objects->search( $authorised_value_categories_set );
return $c->render( status => 200, openapi => $authorised_value_categories );
}
catch {
$c->unhandled_exception($_);
};
}
1;

View File

@ -0,0 +1,20 @@
---
type: object
properties:
category_name:
type: string
description: Unique category name primary key
readOnly: true
is_system:
description: Is this category system or not
type: boolean
readOnly: true
authorised_values:
type: array
description: This category's authorised values
items:
$ref: authorised_value.yaml
additionalProperties: false
required:
- category_name

View File

@ -0,0 +1,60 @@
---
/authorised_value_categories:
get:
x-mojo-to: AuthorisedValueCategories#list
operationId: listAuthorisedValueCategories
tags:
- authorised_value_categories
summary: List authorised value categories
produces:
- application/json
parameters:
- name: x-koha-embed
in: header
required: false
description: Embed list sent as a request header
type: array
items:
type: string
enum:
- authorised_values
collectionFormat: csv
- $ref: "../swagger.yaml#/parameters/match"
- $ref: "../swagger.yaml#/parameters/order_by"
- $ref: "../swagger.yaml#/parameters/page"
- $ref: "../swagger.yaml#/parameters/per_page"
- $ref: "../swagger.yaml#/parameters/q_param"
- $ref: "../swagger.yaml#/parameters/q_body"
- $ref: "../swagger.yaml#/parameters/q_header"
responses:
200:
description: A list of authorised value categories
schema:
items:
$ref: "../swagger.yaml#/definitions/authorised_value_category"
type: array
400:
description: Bad request
schema:
$ref: "../swagger.yaml#/definitions/error"
403:
description: Access forbidden
schema:
$ref: "../swagger.yaml#/definitions/error"
404:
description: Resource not found
schema:
$ref: "../swagger.yaml#/definitions/error"
500:
description: |-
Internal server error. Possible `error_code` attribute values:
* `internal_server_error`
schema:
$ref: "../swagger.yaml#/definitions/error"
503:
description: Under maintenance
schema:
$ref: "../swagger.yaml#/definitions/error"
x-koha-authorization:
permissions:
catalogue: 1

View File

@ -10,6 +10,8 @@ definitions:
$ref: ./definitions/allows_renewal.yaml
authorised_value:
$ref: ./definitions/authorised_value.yaml
authorised_value_category:
$ref: ./definitions/authorised_value_category.yaml
identity_provider:
"$ref": ./definitions/identity_provider.yaml
identity_provider_domain:
@ -141,6 +143,8 @@ paths:
$ref: paths/auth.yaml#/~1auth~1identity_providers~1{identity_provider_id}~1domains
"/auth/identity_providers/{identity_provider_id}/domains/{identity_provider_domain_id}":
$ref: paths/auth.yaml#/~1auth~1identity_providers~1{identity_provider_id}~1domains~1{identity_provider_domain_id}
/authorised_value_categories:
$ref: paths/authorised_value_categories.yaml#/~1authorised_value_categories
"/authorised_value_categories/{authorised_value_category_name}/values":
$ref: "./paths/authorised_values.yaml#/~1authorised_value_categories~1{authorised_value_category_name}~1values"
"/biblios/{biblio_id}":