Bug 30477: Add new UNIMARC installer translation files
[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 Koha::AuthorisedValues;
26
27 =head1 NAME
28
29 svc/authorised_values - Web service for adding authorised values
30
31 =head1 DESCRIPTION
32
33 =cut
34
35 our ( $query, $response ) = C4::Service->init( parameters => 'manage_auth_values' );
36
37 sub add_authorised_value {
38     my $category         = $query->param('category');
39     my $value            = $query->param('value');
40     my $description      = $query->param('description');
41     my $opac_description = $query->param('opac_description');
42     my $image_url        = $query->param('image_url');
43
44     eval {
45         my $av = Koha::AuthorisedValue->new(
46             {
47                 category         => $category,
48                 authorised_value => $value,
49                 lib              => $description,
50                 lib_opac         => $opac_description,
51                 imageurl         => $image_url,
52             }
53         );
54         $av->store;
55         $response->param(
56             category         => $av->category,
57             value            => $av->authorised_value,
58             description      => $av->lib,
59             opac_description => $av->lib_opac,
60             image_url        => $av->imageurl,
61         );
62     };
63     C4::Service->return_error ( $@ ) if $@;
64
65     C4::Service->return_success( $response );
66 }
67
68 C4::Service->dispatch(
69     [ 'POST /', [ 'category', 'value', 'description', 'opac_description' ], \&add_authorised_value ],
70 );