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
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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." }