Bug 17600: Standardize our EXPORT_OK
[koha.git] / svc / authorised_values
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Copyright 2020 Koha Development Team
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use JSON qw( to_json );
23 use CGI;
24 use C4::Service;
25 use C4::Auth qw( check_cookie_auth );
26 use Koha::AuthorisedValues;
27
28 =head1 NAME
29
30 svc/authorised_values - Web service for adding authorised values
31
32 =head1 DESCRIPTION
33
34 =cut
35
36 our ( $query, $response ) = C4::Service->init( parameters => 'manage_auth_values' );
37
38 sub add_authorised_value {
39     my $category         = $query->param('category');
40     my $value            = $query->param('value');
41     my $description      = $query->param('description');
42     my $opac_description = $query->param('opac_description');
43     my $image_url        = $query->param('image_url');
44
45     eval {
46         my $av = Koha::AuthorisedValue->new(
47             {
48                 category         => $category,
49                 authorised_value => $value,
50                 lib              => $description,
51                 lib_opac         => $opac_description,
52                 imageurl         => $image_url,
53             }
54         );
55         $av->store;
56         $response->param(
57             category         => $av->category,
58             value            => $av->authorised_value,
59             description      => $av->lib,
60             opac_description => $av->lib_opac,
61             image_url        => $av->imageurl,
62         );
63     };
64     C4::Service->return_error ( $@ ) if $@;
65
66     C4::Service->return_success( $response );
67 }
68
69 C4::Service->dispatch(
70     [ 'POST /', [ 'category', 'value', 'description', 'opac_description' ], \&add_authorised_value ],
71 );