Bug 20581: API provide status_alias embed
[koha.git] / Koha / REST / V1 / Stage.pm
1 package Koha::REST::V1::Stage;
2
3 # This file is part of Koha.
4 #
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
8 # version.
9 #
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.
13 #
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.
17
18 use Mojo::Base 'Mojolicious::Controller';
19
20 use Koha::StockRotationRotas;
21 use Koha::StockRotationStages;
22
23 =head1 NAME
24
25 Koha::REST::V1::Stage
26
27 =head2 Operations
28
29 =head3 move
30
31 Move a stage up or down the stockrotation rota.
32
33 =cut
34
35 sub move {
36     my $c = shift->openapi->valid_input or return;
37     my $input = $c->validation->output;
38
39     my $rota  = Koha::StockRotationRotas->find( $input->{rota_id} );
40     my $stage = Koha::StockRotationStages->find( $input->{stage_id} );
41
42     if ( $stage && $rota ) {
43         my $result = $stage->move_to( $input->{position} );
44         return $c->render( openapi => {}, status => 200 ) if $result;
45         return $c->render(
46             openapi => { error => "Bad request - new position invalid" },
47             status  => 400
48         );
49     }
50     else {
51         return $c->render(
52             openapi => { error => "Not found - Invalid rota or stage ID" },
53             status  => 404
54         );
55     }
56 }
57
58 1;