1 package Koha::REST::V1::Biblios;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use Mojo::Base 'Mojolicious::Controller';
23 use C4::Biblio qw(DelBiblio);
25 use MARC::Record::MiJ;
35 Controller function that handles retrieving a single biblio object
40 my $c = shift->openapi->valid_input or return;
43 $attributes = { prefetch => [ 'metadata' ] } # don't prefetch metadata if not needed
44 unless $c->req->headers->accept =~ m/application\/json/;
46 my $biblio = Koha::Biblios->find( { biblionumber => $c->validation->param('biblio_id') }, $attributes );
52 error => "Object not found."
59 if ( $c->req->headers->accept =~ m/application\/json/ ) {
62 json => $biblio->to_api
66 my $record = $biblio->metadata->record;
72 text => $record->as_xml_record
77 text => $record->to_mij
82 text => $record->as_usmarc
88 "application/marcxml+xml",
89 "application/marc-in-json",
99 openapi => { error => "Something went wrong, check the logs ($_)" }
106 Controller function that handles deleting a biblio object
111 my $c = shift->openapi->valid_input or return;
113 my $biblio = Koha::Biblios->find( $c->validation->param('biblio_id') );
115 if ( not defined $biblio ) {
118 openapi => { error => "Object not found" }
123 my $error = DelBiblio( $biblio->id );
128 openapi => { error => $error }
132 return $c->render( status => 204, openapi => "" );
136 if ( $_->isa('DBIx::Class::Exception') ) {
139 openapi => { error => $_->{msg} }
145 openapi => { error => "Something went wrong, check the logs." }