1 package Koha::REST::V1::IllbatchStatuses;
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::IllbatchStatuses;
26 Koha::REST::V1::IllbatchStatuses
32 Return a list of available ILL batch statuses
37 my $c = shift->openapi->valid_input;
39 my @statuses = Koha::IllbatchStatuses->search()->as_list;
41 return $c->render( status => 200, openapi => \@statuses );
46 Get one batch statuses
51 my $c = shift->openapi->valid_input;
53 my $status_code = $c->validation->param('illbatchstatus_code');
55 my $status = Koha::IllbatchStatuses->find( { code => $status_code } );
57 if ( not defined $status ) {
60 openapi => { error => "ILL batch status not found" }
66 openapi => { %{ $status->unblessed } }
72 Add a new batch status
77 my $c = shift->openapi->valid_input or return;
79 my $body = $c->validation->param('body');
81 my $status = Koha::IllbatchStatus->new($body);
84 my $return = $status->create_and_log;
85 if ( $return && $return->{error} ) {
97 $c->unhandled_exception($_);
103 Update a batch status
108 my $c = shift->openapi->valid_input or return;
110 my $status = Koha::IllbatchStatuses->find( { code => $c->validation->param('illbatchstatus_code') } );
112 if ( not defined $status ) {
115 openapi => { error => "ILL batch status not found" }
119 my $params = $c->req->json;
123 # Only permit updating of name
124 $status->update_and_log( { name => $params->{name} } );
131 $c->unhandled_exception($_);
137 Delete a batch status
143 my $c = shift->openapi->valid_input or return;
145 my $status = Koha::IllbatchStatuses->find( { code => $c->validation->param('illbatchstatus_code') } );
147 if ( not defined $status ) {
148 return $c->render( status => 404, openapi => { errors => [ { message => "ILL batch status not found" } ] } );
151 if ( $status->is_system ) {
154 openapi => { errors => [ { message => "ILL batch status cannot be deleted" } ] }
159 $status->delete_and_log;
160 return $c->render( status => 204, openapi => '' );
162 $c->unhandled_exception($_);