From c9414b05d539990bf7f2d7c2e501d7d93fc860eb Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Wed, 14 May 2025 10:37:39 +0000 Subject: [PATCH] Bug 39900: REST API specs and class changes Signed-off-by: David Nind --- Koha/AdditionalContent.pm | 37 ++++++++++ Koha/REST/V1/AdditionalContents.pm | 60 ++++++++++++++++ .../definitions/additional_content.yaml | 43 ++++++++++++ api/v1/swagger/paths/additional_contents.yaml | 68 +++++++++++++++++++ api/v1/swagger/swagger.yaml | 4 ++ 5 files changed, 212 insertions(+) create mode 100644 Koha/REST/V1/AdditionalContents.pm create mode 100644 api/v1/swagger/definitions/additional_content.yaml create mode 100644 api/v1/swagger/paths/additional_contents.yaml diff --git a/Koha/AdditionalContent.pm b/Koha/AdditionalContent.pm index 3b2807a849..c81ba995eb 100644 --- a/Koha/AdditionalContent.pm +++ b/Koha/AdditionalContent.pm @@ -142,6 +142,43 @@ sub translated_content { return $content; } +=head3 public_read_list + +This method returns the list of publicly readable database fields for both API and UI output purposes + +=cut + +sub public_read_list { + return [ + 'id', 'category', 'code', + 'location', 'branchcode', 'published_on', + 'updated_on', 'expirationdate', 'number', + 'borrowernumber' + ]; +} + +=head3 to_api_mapping + +This method returns the mapping for representing a Koha::AdditionalContent object +on the API. + +=cut + +sub to_api_mapping { + return { + id => 'additional_content_id', + category => 'category', + code => 'code', + location => 'location', + branchcode => 'library_id', + published_on => 'published_on', + updated_on => 'updated_on', + expirationdate => 'expirationdate', + number => 'number', + borrowernumber => 'patron_id', + }; +} + =head3 _type =cut diff --git a/Koha/REST/V1/AdditionalContents.pm b/Koha/REST/V1/AdditionalContents.pm new file mode 100644 index 0000000000..9473651988 --- /dev/null +++ b/Koha/REST/V1/AdditionalContents.pm @@ -0,0 +1,60 @@ +package Koha::REST::V1::AdditionalContents; + +# 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::AdditionalContents; + +use Try::Tiny qw( catch try ); + +=head1 API + +=head2 Methods + +=head3 list_public + +Controller function that handles retrieving a list of additional contents + +=cut + +sub list_public { + my $c = shift->openapi->valid_input or return; + + return try { + + my @public_locations = ( + @{ Koha::AdditionalContents::get_html_customizations_options('opac') }, + 'staff_and_opac', + 'opac_only' + ); + + my $public_additional_contents_query = + Koha::AdditionalContents::get_public_query_search_params( { location => { '-in' => \@public_locations } } ); + + my $additional_contents = + $c->objects->search( Koha::AdditionalContents->search($public_additional_contents_query) ); + + return $c->render( status => 200, openapi => $additional_contents ); + } catch { + $c->unhandled_exception($_); + }; + +} + +1; diff --git a/api/v1/swagger/definitions/additional_content.yaml b/api/v1/swagger/definitions/additional_content.yaml new file mode 100644 index 0000000000..b440ace5db --- /dev/null +++ b/api/v1/swagger/definitions/additional_content.yaml @@ -0,0 +1,43 @@ +--- +additionalProperties: false +properties: + additional_content_id: + description: Internal identifier for the additional content + type: integer + category: + description: Category of the additional content + type: string + code: + description: Code of the additional content + type: string + location: + description: Location of the additional content + type: string + library_id: + description: Library id of the additional content + type: + - string + - "null" + published_on: + description: Publication date of the additional content + type: string + updated_on: + description: Last modification date of the additional content + type: string + expirationdate: + description: Expiration date of the additional content + type: string + number: + description: The order in which this additional content appears in that specific location + type: integer + patron_id: + description: The author of the additional content + type: + - string + - "null" +required: + - additional_content_id + - category + - code + - location +type: object diff --git a/api/v1/swagger/paths/additional_contents.yaml b/api/v1/swagger/paths/additional_contents.yaml new file mode 100644 index 0000000000..657970cae0 --- /dev/null +++ b/api/v1/swagger/paths/additional_contents.yaml @@ -0,0 +1,68 @@ +--- +"/public/additional_contents": + get: + x-mojo-to: AdditionalContents#list_public + operationId: listAdditionalContents + parameters: + - description: Case insensitive search on additional_contents id + in: query + name: additional_content_id + required: false + type: string + - description: Case insensitive search on additional_contents category + in: query + name: category + required: false + type: string + - description: Case insensitive search on additional_contents code + in: query + name: code + required: false + type: string + - description: Case insensitive search on additional_contents location + in: query + name: location + required: false + type: string + - description: Case insensitive search on additional_contents library_id + in: query + name: library_id + required: false + type: string + - $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" + produces: + - application/json + responses: + 200: + description: A list of additional contents + schema: + items: + $ref: ../swagger.yaml#/definitions/additional_content + type: array + 400: + description: | + Bad request. Possible `error_code` attribute values: + + * `invalid_query` + schema: + $ref: "../swagger.yaml#/definitions/error" + 403: + description: Access forbidden + schema: + $ref: ../swagger.yaml#/definitions/error + 500: + description: Internal error + schema: + $ref: ../swagger.yaml#/definitions/error + 503: + description: Under maintenance + schema: + $ref: ../swagger.yaml#/definitions/error + summary: List public additional contents + tags: + - additional_contents \ No newline at end of file diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index fb36579cea..de776c3827 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -4,6 +4,8 @@ basePath: /api/v1 definitions: account_line: $ref: ./definitions/account_line.yaml + additional_content: + $ref: ./definitions/additional_content.yaml advancededitormacro: $ref: ./definitions/advancededitormacro.yaml allows_renewal: @@ -511,6 +513,8 @@ paths: $ref: ./paths/preservation_waiting_list.yaml#/~1preservation~1waiting-list~1items "/preservation/waiting-list/items/{item_id}": $ref: "./paths/preservation_waiting_list.yaml#/~1preservation~1waiting-list~1items~1{item_id}" + "/public/additional_contents": + $ref: ./paths/additional_contents.yaml#/~1public~1additional_contents "/public/biblios/{biblio_id}": $ref: "./paths/biblios.yaml#/~1public~1biblios~1{biblio_id}" "/public/checkouts/availability": -- 2.39.5