Lines 21-27
use Mojo::Base 'Mojolicious::Controller';
Link Here
|
21 |
|
21 |
|
22 |
use Koha::CirculationRules; |
22 |
use Koha::CirculationRules; |
23 |
|
23 |
|
24 |
|
|
|
25 |
=head1 API |
24 |
=head1 API |
26 |
|
25 |
|
27 |
=head2 Methods |
26 |
=head2 Methods |
Lines 36-44
sub get_kinds {
Link Here
|
36 |
my $c = shift->openapi->valid_input or return; |
35 |
my $c = shift->openapi->valid_input or return; |
37 |
|
36 |
|
38 |
return $c->render( |
37 |
return $c->render( |
39 |
status => 200, |
38 |
status => 200, |
40 |
openapi => Koha::CirculationRules->rule_kinds, |
39 |
openapi => Koha::CirculationRules->rule_kinds, |
41 |
); |
40 |
); |
42 |
} |
41 |
} |
43 |
|
42 |
|
|
|
43 |
=head3 list_effective_rules |
44 |
|
45 |
List all effective rules for the requested patron/item/branch combination |
46 |
|
47 |
=cut |
48 |
|
49 |
sub list_effective_rules { |
50 |
my $c = shift->openapi->valid_input or return; |
51 |
|
52 |
my $item_type = $c->param('itemtype'); |
53 |
my $branchcode = $c->param('library'); |
54 |
my $patron_category = $c->param('category'); |
55 |
my $rules = $c->param('rules') // [ keys %{ Koha::CirculationRules->rule_kinds } ]; |
56 |
|
57 |
if ($item_type) { |
58 |
my $type = Koha::ItemTypes->find($item_type); |
59 |
return $c->render_invalid_parameter_value( |
60 |
{ |
61 |
path => '/query/item_type', |
62 |
values => { |
63 |
uri => '/api/v1/item_types', |
64 |
field => 'item_type_id' |
65 |
} |
66 |
} |
67 |
) unless $type; |
68 |
} |
69 |
|
70 |
if ($branchcode) { |
71 |
my $library = Koha::Libraries->find($branchcode); |
72 |
return $c->render_invalid_parameter_value( |
73 |
{ |
74 |
path => '/query/library', |
75 |
values => { |
76 |
uri => '/api/v1/libraries', |
77 |
field => 'library_id' |
78 |
} |
79 |
} |
80 |
) unless $library; |
81 |
} |
82 |
|
83 |
if ($patron_category) { |
84 |
my $category = Koha::Patron::Categories->find($patron_category); |
85 |
return $c->render_invalid_parameter_value( |
86 |
{ |
87 |
path => '/query/patron_category', |
88 |
values => { |
89 |
uri => '/api/v1/patron_categories', |
90 |
field => 'patron_category_id' |
91 |
} |
92 |
} |
93 |
) unless $category; |
94 |
} |
95 |
|
96 |
my $effective_rules = Koha::CirculationRules->get_effective_rules( |
97 |
{ |
98 |
categorycode => $patron_category, |
99 |
itemtype => $item_type, |
100 |
branchcode => $branchcode, |
101 |
rules => $rules |
102 |
} |
103 |
); |
104 |
|
105 |
return $c->render( |
106 |
status => 200, |
107 |
openapi => $effective_rules ? $effective_rules : {} |
108 |
); |
109 |
} |
110 |
|
44 |
1; |
111 |
1; |