Bug 39900: REST API specs and class changes
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 316745f3e2)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
parent
b08f5872d3
commit
05b2abd841
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 <http://www.gnu.org/licenses>.
|
||||
|
||||
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;
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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:
|
||||
|
|
@ -513,6 +515,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":
|
||||
|
|
|
|||
Loading…
Reference in New Issue