1 package Koha::REST::V1::Illbackends;
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';
22 use Koha::Illrequest::Config;
23 use Koha::Illrequests;
27 Koha::REST::V1::Illbackends
33 Return a list of available ILL backends and its capabilities
38 my $c = shift->openapi->valid_input;
40 my $config = Koha::Illrequest::Config->new;
41 my $backends = $config->available_backends;
44 foreach my $b ( @$backends ) {
45 my $backend = Koha::Illrequest->new->load_backend( $b );
48 capabilities => $backend->capabilities,
51 return $c->render( status => 200, openapi => \@data );
56 Return a list of existing ILL statuses
61 my $c = shift->openapi->valid_input;
63 my $backend_id = $c->validation->param('ill_backend_id');
65 #FIXME: Currently fetching all requests, it'd be great if we could fetch distinct(status).
66 # Even doing it with distinct status, we need the ILL request object, so that strings_map works and
67 # the ILL request returns the correct status and info respective to its backend.
68 my $ill_requests = Koha::Illrequests->search(
69 {backend => $backend_id},
71 # columns => [ qw/status/ ],
72 # group_by => [ qw/status/ ],
77 while (my $request = $ill_requests->next) {
78 my $status_data = $request->strings_map;
80 foreach my $status_class ( qw(status_alias status) ){
81 if ($status_data->{$status_class}){
83 $status_data->{$status_class}->{str} ? (str => $status_data->{$status_class}->{str}) :
84 $status_data->{$status_class}->{code} ? (str => $status_data->{$status_class}->{code}) : (),
85 $status_data->{$status_class}->{code} ? (code => $status_data->{$status_class}->{code}) : (),
91 # Remove duplicate statuses
93 @data = grep { my $e = $_; my $key = join '___', map { $e->{$_}; } sort keys %$_;!$seen{$key}++ } @data;
95 return $c->render( status => 200, openapi => \@data );
105 my $c = shift->openapi->valid_input;
107 my $backend_id = $c->validation->param('ill_backend_id');
110 my $backend = Koha::Illrequest->new->load_backend( $backend_id );
114 ill_backend_id => $backend_id,
115 capabilities => $backend->capabilities
121 openapi => { error => "ILL backend does not exist" }