1 package Koha::REST::V1::Authorities;
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';
22 use Koha::Authorities;
23 use C4::AuthoritiesMarc qw( DelAuthority );
25 use List::MoreUtils qw( any );
26 use MARC::Record::MiJ;
28 use Try::Tiny qw( catch try );
36 Controller function that handles retrieving a single authority object
41 my $c = shift->openapi->valid_input or return;
43 my $authority = Koha::Authorities->find( { authid => $c->validation->param('authority_id') } );
44 unless ( $authority ) {
48 error => "Object not found."
55 if ( $c->req->headers->accept =~ m/application\/json/ ) {
58 json => $authority->to_api
62 my $record = $authority->record;
68 text => $record->as_xml_record
73 data => $record->to_mij
78 text => $record->as_usmarc
82 format => 'text/plain',
83 text => $record->as_formatted
89 "application/marcxml+xml",
90 "application/marc-in-json",
99 $c->unhandled_exception($_);
105 Controller function that handles deleting an authority object
110 my $c = shift->openapi->valid_input or return;
112 my $authority = Koha::Authorities->find( { authid => $c->validation->param('authority_id') } );
114 if ( not defined $authority ) {
117 openapi => { error => "Object not found" }
122 my $error = DelAuthority( { authid => $authority->authid } );
127 openapi => { error => $error }
131 return $c->render( status => 204, openapi => "" );
135 $c->unhandled_exception($_);