Bug 17600: Standardize our EXPORT_OK
[srvgit] / Koha / REST / V1 / CashRegisters / Cashups.pm
1 package Koha::REST::V1::CashRegisters::Cashups;
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
14 #
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>.
17
18 use Modern::Perl;
19
20 use Mojo::Base 'Mojolicious::Controller';
21
22 use Try::Tiny qw( catch try );
23
24 use Koha::Cash::Registers;
25
26 =head1 NAME
27
28 Koha::REST::V1::CashRegisters::Cashups
29
30 =head1 API
31
32 =head2 Methods
33
34 =head3 list
35
36 Controller function that handles retrieving a cash registers cashup actions
37
38 =cut
39
40 sub list {
41     my $c = shift->openapi->valid_input or return;
42
43     my $register = Koha::Cash::Registers->find(
44         {
45             id => $c->validation->param('cash_register_id')
46         }
47     );
48
49     unless ($register) {
50         return $c->render(
51             status  => 404,
52             openapi => {
53                 error => "Register not found"
54             }
55         );
56     }
57
58     return try {
59         my $cashups_rs = $register->cashups;
60         my $cashups    = $c->objects->search($cashups_rs);
61         return $c->render( status => 200, openapi => $cashups );
62     }
63     catch {
64         $c->unhandled_exception($_);
65     };
66 }
67
68 =head3 get
69
70 Controller function that handles retrieving a cash register cashup
71
72 =cut
73
74 sub get {
75     my $c = shift->openapi->valid_input or return;
76
77     return try {
78         my $cashup = Koha::Cash::Register::Cashups->find(
79             $c->validation->param('cashup_id') );
80         unless ($cashup) {
81             return $c->render(
82                 status  => 404,
83                 openapi => { error => "Cashup not found" }
84             );
85         }
86
87         my $embed = $c->stash('koha.embed');
88         return $c->render(
89             status  => 200,
90             openapi => $cashup->to_api( { embed => $embed } )
91         );
92     }
93     catch {
94         $c->unhandled_exception($_);
95     }
96 }
97
98 1;