Bugzilla – Attachment 160000 Details for
Bug 33960
Add ability to retrieve deleted bibliographic records
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33960: Add routes and controller
Bug-33960-Add-routes-and-controller.patch (text/plain), 10.31 KB, created by
Nick Clemens (kidclamp)
on 2023-12-19 13:48:20 UTC
(
hide
)
Description:
Bug 33960: Add routes and controller
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2023-12-19 13:48:20 UTC
Size:
10.31 KB
patch
obsolete
>From 8c69af9d2757ee7adc184388ec7c907ff97f5624 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Fri, 15 Dec 2023 16:56:11 +0000 >Subject: [PATCH] Bug 33960: Add routes and controller > >--- > Koha/REST/V1/DeletedBiblios.pm | 186 ++++++++++++++++++++++ > api/v1/swagger/paths/deleted_biblios.yaml | 109 +++++++++++++ > api/v1/swagger/swagger.yaml | 4 + > 3 files changed, 299 insertions(+) > create mode 100644 Koha/REST/V1/DeletedBiblios.pm > create mode 100644 api/v1/swagger/paths/deleted_biblios.yaml > >diff --git a/Koha/REST/V1/DeletedBiblios.pm b/Koha/REST/V1/DeletedBiblios.pm >new file mode 100644 >index 00000000000..21e6dd1f3f6 >--- /dev/null >+++ b/Koha/REST/V1/DeletedBiblios.pm >@@ -0,0 +1,186 @@ >+package Koha::REST::V1::DeletedBiblios; >+ >+# 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::Old::Biblios; >+use Koha::DateUtils; >+use Koha::RecordProcessor; >+ >+use C4::Context; >+ >+use Koha::Items; >+ >+use List::MoreUtils qw( any ); >+use MARC::Record::MiJ; >+ >+use Try::Tiny qw( catch try ); >+ >+=head1 API >+ >+=head2 Methods >+ >+=head3 get >+ >+Controller function that handles retrieving a single biblio object >+ >+=cut >+ >+sub get { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $attributes; >+ $attributes = { prefetch => [ 'metadata' ] } # don't prefetch metadata if not needed >+ unless $c->req->headers->accept =~ m/application\/json/; >+ >+ my $biblio = Koha::Old::Biblios->find( { biblionumber => $c->param('biblio_id') }, $attributes ); >+ >+ unless ( $biblio ) { >+ return $c->render( >+ status => 404, >+ openapi => { >+ error => "Object not found." >+ } >+ ); >+ } >+ >+ return try { >+ >+ if ( $c->req->headers->accept =~ m/application\/json/ ) { >+ return $c->render( >+ status => 200, >+ json => $biblio->to_api >+ ); >+ } >+ else { >+ my $metadata = $biblio->metadata; >+ my $record = $metadata->record; >+ my $schema = $metadata->schema // C4::Context->preference("marcflavour"); >+ >+ $c->respond_to( >+ marcxml => { >+ status => 200, >+ format => 'marcxml', >+ text => $record->as_xml_record($schema), >+ }, >+ mij => { >+ status => 200, >+ format => 'mij', >+ data => $record->to_mij >+ }, >+ marc => { >+ status => 200, >+ format => 'marc', >+ text => $record->as_usmarc >+ }, >+ txt => { >+ status => 200, >+ format => 'text/plain', >+ text => $record->as_formatted >+ }, >+ any => { >+ status => 406, >+ openapi => [ >+ "application/json", >+ "application/marcxml+xml", >+ "application/marc-in-json", >+ "application/marc", >+ "text/plain" >+ ] >+ } >+ ); >+ } >+ } >+ catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ >+=head3 list >+ >+Controller function that handles listing a deleted biblio objects >+ >+=cut >+ >+sub list { >+ my $c = shift->openapi->valid_input or return; >+ >+ my @prefetch = qw(biblioitem); >+ push @prefetch, 'metadata' # don't prefetch metadata if not needed >+ unless $c->req->headers->accept =~ m/application\/json/; >+ >+ my $rs = Koha::Old::Biblios->search( undef, { prefetch => \@prefetch }); >+ my $biblios = $c->objects->search_rs( $rs, [(sub{ $rs->api_query_fixer( $_[0], '', $_[1] ) })] ); >+ >+ return try { >+ >+ if ( $c->req->headers->accept =~ m/application\/json(;.*)?$/ ) { >+ return $c->render( >+ status => 200, >+ json => $c->objects->to_api( $biblios ), >+ ); >+ } >+ elsif ( >+ $c->req->headers->accept =~ m/application\/marcxml\+xml(;.*)?$/ ) >+ { >+ $c->res->headers->add( 'Content-Type', 'application/marcxml+xml' ); >+ return $c->render( >+ status => 200, >+ text => $biblios->print_collection('marcxml') >+ ); >+ } >+ elsif ( >+ $c->req->headers->accept =~ m/application\/marc-in-json(;.*)?$/ ) >+ { >+ $c->res->headers->add( 'Content-Type', 'application/marc-in-json' ); >+ return $c->render( >+ status => 200, >+ data => $biblios->print_collection('mij') >+ ); >+ } >+ elsif ( $c->req->headers->accept =~ m/application\/marc(;.*)?$/ ) { >+ $c->res->headers->add( 'Content-Type', 'application/marc' ); >+ return $c->render( >+ status => 200, >+ text => $biblios->print_collection('marc') >+ ); >+ } >+ elsif ( $c->req->headers->accept =~ m/text\/plain(;.*)?$/ ) { >+ return $c->render( >+ status => 200, >+ text => $biblios->print_collection('txt') >+ ); >+ } >+ else { >+ return $c->render( >+ status => 406, >+ openapi => [ >+ "application/json", "application/marcxml+xml", >+ "application/marc-in-json", "application/marc", >+ "text/plain" >+ ] >+ ); >+ } >+ } >+ catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ >+1; >diff --git a/api/v1/swagger/paths/deleted_biblios.yaml b/api/v1/swagger/paths/deleted_biblios.yaml >new file mode 100644 >index 00000000000..5678a2a22a4 >--- /dev/null >+++ b/api/v1/swagger/paths/deleted_biblios.yaml >@@ -0,0 +1,109 @@ >+--- >+"/deleted/biblios": >+ get: >+ x-mojo-to: DeletedBiblios#list >+ operationId: listDeletedBiblios >+ tags: >+ - biblios >+ summary: List deleted biblios >+ parameters: >+ - $ref: "../swagger.yaml#/parameters/page" >+ - $ref: "../swagger.yaml#/parameters/per_page" >+ - $ref: "../swagger.yaml#/parameters/match" >+ - $ref: "../swagger.yaml#/parameters/order_by" >+ - $ref: "../swagger.yaml#/parameters/q_param" >+ - $ref: "../swagger.yaml#/parameters/q_body" >+ - $ref: "../swagger.yaml#/parameters/request_id_header" >+ produces: >+ - application/json >+ - application/marcxml+xml >+ - application/marc-in-json >+ - application/marc >+ - text/plain >+ responses: >+ "200": >+ description: A list of deleted biblios >+ "401": >+ description: Authentication required >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "403": >+ description: Access forbidden >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "404": >+ description: Biblio not found >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "406": >+ description: Not acceptable >+ schema: >+ type: array >+ description: Accepted content-types >+ items: >+ type: string >+ "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" >+"/deleted/biblios/{biblio_id}": >+ get: >+ x-mojo-to: DeletedBiblios#get >+ operationId: getDeletedBiblio >+ tags: >+ - biblios >+ summary: Get deleted biblio >+ parameters: >+ - $ref: "../swagger.yaml#/parameters/biblio_id_pp" >+ produces: >+ - application/json >+ - application/marcxml+xml >+ - application/marc-in-json >+ - application/marc >+ - text/plain >+ responses: >+ "200": >+ description: A deleted biblio >+ "401": >+ description: Authentication required >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "403": >+ description: Access forbidden >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "404": >+ description: Biblio not found >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "406": >+ description: Not acceptable >+ schema: >+ type: array >+ description: Accepted content-types >+ items: >+ type: string >+ "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" >diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml >index 46966e40b2b..fbf2ad8389f 100644 >--- a/api/v1/swagger/swagger.yaml >+++ b/api/v1/swagger/swagger.yaml >@@ -271,6 +271,10 @@ paths: > $ref: ./paths/config_smtp_servers.yaml#/~1config~1smtp_servers > "/config/smtp_servers/{smtp_server_id}": > $ref: "./paths/config_smtp_servers.yaml#/~1config~1smtp_servers~1{smtp_server_id}" >+ "/deleted/biblios": >+ $ref: "./paths/deleted_biblios.yaml#/~1deleted~1biblios" >+ "/deleted/biblios/{biblio_id}": >+ $ref: "./paths/deleted_biblios.yaml#/~1deleted~1biblios~1{biblio_id}" > /erm/config: > $ref: ./paths/erm_config.yaml#/~1erm~1config > /erm/agreements: >-- >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 33960
:
152199
|
152200
|
152201
|
152215
|
155331
|
155332
|
155333
|
155334
|
155335
|
155416
|
155417
|
155418
|
155419
|
155420
|
157899
|
157900
|
157901
|
157902
|
157903
|
157904
|
158071
|
159998
|
159999
|
160000
|
160001
|
160002
|
160552
|
163852
|
163853
|
163854
|
163855
|
163948
|
163949
|
163950
|
163951