@@ -, +, @@ for multiple given categories --- Koha/AuthorisedValueCategory.pm | 13 ++++ Koha/REST/V1/AuthorisedValueCategories.pm | 49 +++++++++++++++ .../authorised_value_category.yaml | 20 +++++++ .../paths/authorised_value_categories.yaml | 60 +++++++++++++++++++ api/v1/swagger/swagger.yaml | 4 ++ 5 files changed, 146 insertions(+) create mode 100644 Koha/REST/V1/AuthorisedValueCategories.pm create mode 100644 api/v1/swagger/definitions/authorised_value_category.yaml create mode 100644 api/v1/swagger/paths/authorised_value_categories.yaml --- a/Koha/AuthorisedValueCategory.pm +++ a/Koha/AuthorisedValueCategory.pm @@ -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 --- a/Koha/REST/V1/AuthorisedValueCategories.pm +++ a/Koha/REST/V1/AuthorisedValueCategories.pm @@ -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 . + +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; --- a/api/v1/swagger/definitions/authorised_value_category.yaml +++ a/api/v1/swagger/definitions/authorised_value_category.yaml @@ -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 --- a/api/v1/swagger/paths/authorised_value_categories.yaml +++ a/api/v1/swagger/paths/authorised_value_categories.yaml @@ -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 --- a/api/v1/swagger/swagger.yaml +++ a/api/v1/swagger/swagger.yaml @@ -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}": --