Bugzilla – Attachment 158514 Details for
Bug 35197
Expose additional_field definitions through REST API
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35197: Add additional_fields REST API endpoint
Bug-35197-Add-additionalfields-REST-API-endpoint.patch (text/plain), 6.66 KB, created by
Pedro Amorim
on 2023-11-06 12:18:14 UTC
(
hide
)
Description:
Bug 35197: Add additional_fields REST API endpoint
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2023-11-06 12:18:14 UTC
Size:
6.66 KB
patch
obsolete
>From 8086923855551360bfa8ec716962a952c60f4501 Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Tue, 31 Oct 2023 10:56:31 -0100 >Subject: [PATCH] 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 >--- > Koha/REST/V1/AdditionalFields.pm | 52 +++++++++++++++++++ > .../swagger/definitions/additional_field.yaml | 35 +++++++++++++ > api/v1/swagger/paths/additional_fields.yaml | 49 +++++++++++++++++ > api/v1/swagger/swagger.yaml | 4 ++ > 4 files changed, 140 insertions(+) > create mode 100644 Koha/REST/V1/AdditionalFields.pm > create mode 100644 api/v1/swagger/definitions/additional_field.yaml > create mode 100644 api/v1/swagger/paths/additional_fields.yaml > >diff --git a/Koha/REST/V1/AdditionalFields.pm b/Koha/REST/V1/AdditionalFields.pm >new file mode 100644 >index 0000000000..db9e2ed8d2 >--- /dev/null >+++ b/Koha/REST/V1/AdditionalFields.pm >@@ -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; >diff --git a/api/v1/swagger/definitions/additional_field.yaml b/api/v1/swagger/definitions/additional_field.yaml >new file mode 100644 >index 0000000000..5fa3a3e699 >--- /dev/null >+++ b/api/v1/swagger/definitions/additional_field.yaml >@@ -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 >\ No newline at end of file >diff --git a/api/v1/swagger/paths/additional_fields.yaml b/api/v1/swagger/paths/additional_fields.yaml >new file mode 100644 >index 0000000000..3f5b5b651f >--- /dev/null >+++ b/api/v1/swagger/paths/additional_fields.yaml >@@ -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 >\ No newline at end of file >diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml >index 46966e40b2..0fb422e2c3 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_field: >+ $ref: ./definitions/additional_field.yaml > advancededitormacro: > $ref: ./definitions/advancededitormacro.yaml > allows_renewal: >@@ -179,6 +181,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: >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35197
:
158112
|
158511
|
158512
|
158514
|
158515
|
158577
|
158578
|
159648
|
159649
|
159650
|
165726
|
165727
|
165728
|
165769
|
165780
|
168057
|
168058
|
168059
|
168060
|
168061
|
168062
|
168063
|
168064
|
168065