Bug 32030: Some refactoring and improvements
[koha.git] / Koha / REST / V1 / ERM / EHoldings / Packages.pm
1 package Koha::REST::V1::ERM::EHoldings::Packages;
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 Scalar::Util qw( blessed );
23 use Try::Tiny qw( catch try );
24
25 use Koha::REST::V1::ERM::EHoldings::Packages::Manual;
26 use Koha::REST::V1::ERM::EHoldings::Packages::EBSCO;
27
28 =head1 API
29
30 =head2 Methods
31
32 =head3 list
33
34 =cut
35
36 sub list {
37     my $provider = C4::Context->preference('ERMProvider');
38     if ( $provider eq 'ebsco' ) {
39         return Koha::REST::V1::ERM::EHoldings::Packages::EBSCO::list(@_);
40     } else {
41         return Koha::REST::V1::ERM::EHoldings::Packages::Manual::list(@_);
42     }
43 }
44
45 =head3 get
46
47 Controller function that handles retrieving a single Koha::ERM::EHoldings::Package object
48
49 =cut
50
51 sub get {
52     my $provider = C4::Context->preference('ERMProvider');
53     if ( $provider eq 'ebsco' ) {
54         return Koha::REST::V1::ERM::EHoldings::Packages::EBSCO::get(@_);
55     } else {
56         return Koha::REST::V1::ERM::EHoldings::Packages::Manual::get(@_);
57     }
58 }
59
60 =head3 add
61
62 Controller function that handles adding a new Koha::ERM::EHoldings::Package object
63
64 =cut
65
66 sub add {
67     my $provider = C4::Context->preference('ERMProvider');
68     if ( $provider eq 'ebsco' ) {
69         die "invalid action";
70     } else {
71         return Koha::REST::V1::ERM::EHoldings::Packages::Manual::add(@_);
72     }
73 }
74
75 =head3 update
76
77 Controller function that handles updating a Koha::ERM::EHoldings::Package object
78
79 =cut
80
81 sub update {
82     my $provider = C4::Context->preference('ERMProvider');
83     if ( $provider eq 'ebsco' ) {
84         die "invalid action";
85     } else {
86         return Koha::REST::V1::ERM::EHoldings::Packages::Manual::update(@_);
87     }
88 };
89
90 =head3 delete
91
92 =cut
93
94 sub delete {
95     my $provider = C4::Context->preference('ERMProvider');
96     if ( $provider eq 'ebsco' ) {
97         die "invalid action";
98     } else {
99         return Koha::REST::V1::ERM::EHoldings::Packages::Manual::delete(@_);
100     }
101 }
102
103 1;