Bug 35197: Add additional_fields REST API endpoint
Test plan: 1) Apply patch, restart plack 'koha-plack --restart kohadev' 2) Visit /api/v1/additional_fields?tablename=aqinvoices - Notice its empty 3) Visit /cgi-bin/koha/admin/additional-fields.pl?tablename=aqbasket and add a new additional field 4) Do step 2) again - Notice the newly created additional field is there 5) Visit /cgi-bin/koha/admin/additional-fields.pl?tablename=aqinvoices and add a new additional field for invoices 6) Do step 2) again - Notice both additional fields are there 7) Visit /api/v1/additional_fields?tablename=aqinvoices - Notice only the additional field for aqinvoices is listed Signed-off-by: Lucas Gass <lucas@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
444f3d8bad
commit
3c87aa8c7f
|
|
@ -0,0 +1,52 @@
|
|||
package Koha::REST::V1::AdditionalFields;
|
||||
|
||||
# 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::AdditionalFields;
|
||||
|
||||
use Try::Tiny qw( catch try );
|
||||
|
||||
=head1 API
|
||||
|
||||
=head2 Methods
|
||||
|
||||
=head3 list
|
||||
|
||||
=cut
|
||||
|
||||
sub list {
|
||||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $tablename = $c->param('tablename');
|
||||
|
||||
return try {
|
||||
my $additional_fields_set = Koha::AdditionalFields->new;
|
||||
if ($tablename) {
|
||||
$additional_fields_set = $additional_fields_set->search( { tablename => $tablename } );
|
||||
}
|
||||
my $additional_fields = $c->objects->search($additional_fields_set);
|
||||
return $c->render( status => 200, openapi => $additional_fields );
|
||||
} catch {
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
description: internally assigned additional field identifier
|
||||
readOnly: true
|
||||
tablename:
|
||||
description: name of the table this additional field corresponds to
|
||||
type: string
|
||||
name:
|
||||
description: name of the additional field
|
||||
type: string
|
||||
authorised_value_category:
|
||||
description: authorised value category of the additional field
|
||||
type:
|
||||
- string
|
||||
- "null"
|
||||
marcfield:
|
||||
description: marcfield of the additional field
|
||||
type: string
|
||||
marcfield_mode:
|
||||
description: marcfield mode of the additional field
|
||||
type: string
|
||||
enum:
|
||||
- get
|
||||
- set
|
||||
searchable:
|
||||
description: is the additional field searchable
|
||||
type: boolean
|
||||
|
||||
additionalProperties: false
|
||||
required:
|
||||
- id
|
||||
- tablename
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
---
|
||||
/additional_fields:
|
||||
get:
|
||||
x-mojo-to: AdditionalFields#list
|
||||
operationId: listAdditionalFields
|
||||
tags:
|
||||
- additional_fields
|
||||
summary: List additional fields
|
||||
produces:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: filter by table name
|
||||
in: query
|
||||
name: tablename
|
||||
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"
|
||||
responses:
|
||||
200:
|
||||
description: A list of additional_fields
|
||||
schema:
|
||||
items:
|
||||
$ref: "../swagger.yaml#/definitions/additional_field"
|
||||
type: array
|
||||
400:
|
||||
description: Bad request
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
403:
|
||||
description: Access forbidden
|
||||
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:
|
||||
tools: manage_additional_fields
|
||||
|
|
@ -4,6 +4,8 @@ basePath: /api/v1
|
|||
definitions:
|
||||
account_line:
|
||||
$ref: ./definitions/account_line.yaml
|
||||
additional_field:
|
||||
$ref: ./definitions/additional_field.yaml
|
||||
advancededitormacro:
|
||||
$ref: ./definitions/advancededitormacro.yaml
|
||||
allows_renewal:
|
||||
|
|
@ -197,6 +199,8 @@ paths:
|
|||
$ref: "./paths/acquisitions_vendors.yaml#/~1acquisitions~1vendors~1{vendor_id}"
|
||||
"/acquisitions/vendors/{vendor_id}/issues":
|
||||
$ref: "./paths/acquisitions_vendor_issues.yaml#/~1acquisitions~1vendors~1{vendor_id}~1issues"
|
||||
/additional_fields:
|
||||
$ref: ./paths/additional_fields.yaml#/~1additional_fields
|
||||
/advanced_editor/macros:
|
||||
$ref: ./paths/advancededitormacros.yaml#/~1advanced_editor~1macros
|
||||
/advanced_editor/macros/shared:
|
||||
|
|
|
|||
Loading…
Reference in New Issue