1 package Koha::REST::V1::ILL::Backends;
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::ILL::Request::Config;
23 use Koha::Illrequests;
24 use Koha::ILL::Backend;
28 Koha::REST::V1::ILL::Backends
34 Return a list of available ILL backends and its capabilities
39 my $c = shift->openapi->valid_input;
41 my $config = Koha::ILL::Request::Config->new;
42 my $backends = $config->available_backends;
43 my $backend_module = Koha::ILL::Backend->new;
46 foreach my $b (@$backends) {
47 my $backend = Koha::Illrequest->new->load_backend($b);
49 my $embed = $backend_module->embed(
51 $c->req->headers->header('x-koha-embed')
56 capabilities => $backend->capabilities,
58 push @data, $embed ? { %$return, %$embed } : $return;
60 return $c->render( status => 200, openapi => \@data );
70 my $c = shift->openapi->valid_input;
72 my $backend_id = $c->param('ill_backend_id');
76 #FIXME: Should we move load_backend into Koha::ILL::Backend...
77 # or maybe make Koha::Ill::Backend a base class for all
79 my $backend = Koha::Illrequest->new->load_backend($backend_id);
81 my $backend_module = Koha::ILL::Backend->new;
83 my $embed = $backend_module->embed(
85 $c->req->headers->header('x-koha-embed')
88 #TODO: We need a to_api method in Koha::ILL::Backend
90 ill_backend_id => $backend_id,
91 capabilities => $backend->capabilities,
96 openapi => $embed ? { %$return, %$embed } : $return,
101 openapi => { error => "ILL backend does not exist" }