|
Lines 49-111
List all effective rules for the requested patron/item/branch combination
Link Here
|
| 49 |
sub list_effective_rules { |
49 |
sub list_effective_rules { |
| 50 |
my $c = shift->openapi->valid_input or return; |
50 |
my $c = shift->openapi->valid_input or return; |
| 51 |
|
51 |
|
| 52 |
my $item_type = $c->param('item_type_id'); |
52 |
return try { |
| 53 |
my $branchcode = $c->param('library_id'); |
53 |
my $item_type = $c->param('item_type_id'); |
| 54 |
my $patron_category = $c->param('patron_category_id'); |
54 |
my $branchcode = $c->param('library_id'); |
| 55 |
my $rules = $c->param('rules') // [ keys %{ Koha::CirculationRules->rule_kinds } ]; |
55 |
my $patron_category = $c->param('patron_category_id'); |
| 56 |
|
56 |
my $rules = $c->param('rules') // [ keys %{ Koha::CirculationRules->rule_kinds } ]; |
| 57 |
if ($item_type) { |
57 |
|
| 58 |
my $type = Koha::ItemTypes->find($item_type); |
58 |
if ($item_type) { |
| 59 |
return $c->render_invalid_parameter_value( |
59 |
my $type = Koha::ItemTypes->find($item_type); |
| 60 |
{ |
60 |
return $c->render_invalid_parameter_value( |
| 61 |
path => '/query/item_type_id', |
61 |
{ |
| 62 |
values => { |
62 |
path => '/query/item_type_id', |
| 63 |
uri => '/api/v1/item_types', |
63 |
values => { |
| 64 |
field => 'item_type_id' |
64 |
uri => '/api/v1/item_types', |
|
|
65 |
field => 'item_type_id' |
| 66 |
} |
| 65 |
} |
67 |
} |
| 66 |
} |
68 |
) unless $type; |
| 67 |
) unless $type; |
69 |
} |
| 68 |
} |
|
|
| 69 |
|
70 |
|
| 70 |
if ($branchcode) { |
71 |
if ($branchcode) { |
| 71 |
my $library = Koha::Libraries->find($branchcode); |
72 |
my $library = Koha::Libraries->find($branchcode); |
| 72 |
return $c->render_invalid_parameter_value( |
73 |
return $c->render_invalid_parameter_value( |
| 73 |
{ |
74 |
{ |
| 74 |
path => '/query/library_id', |
75 |
path => '/query/library_id', |
| 75 |
values => { |
76 |
values => { |
| 76 |
uri => '/api/v1/libraries', |
77 |
uri => '/api/v1/libraries', |
| 77 |
field => 'library_id' |
78 |
field => 'library_id' |
|
|
79 |
} |
| 78 |
} |
80 |
} |
| 79 |
} |
81 |
) unless $library; |
| 80 |
) unless $library; |
82 |
} |
| 81 |
} |
|
|
| 82 |
|
83 |
|
| 83 |
if ($patron_category) { |
84 |
if ($patron_category) { |
| 84 |
my $category = Koha::Patron::Categories->find($patron_category); |
85 |
my $category = Koha::Patron::Categories->find($patron_category); |
| 85 |
return $c->render_invalid_parameter_value( |
86 |
return $c->render_invalid_parameter_value( |
| 86 |
{ |
87 |
{ |
| 87 |
path => '/query/patron_category_id', |
88 |
path => '/query/patron_category_id', |
| 88 |
values => { |
89 |
values => { |
| 89 |
uri => '/api/v1/patron_categories', |
90 |
uri => '/api/v1/patron_categories', |
| 90 |
field => 'patron_category_id' |
91 |
field => 'patron_category_id' |
|
|
92 |
} |
| 91 |
} |
93 |
} |
| 92 |
} |
94 |
) unless $category; |
| 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 |
} |
95 |
} |
| 103 |
); |
|
|
| 104 |
|
96 |
|
| 105 |
return $c->render( |
97 |
my $effective_rules = Koha::CirculationRules->get_effective_rules( |
| 106 |
status => 200, |
98 |
{ |
| 107 |
openapi => $effective_rules ? $effective_rules : {} |
99 |
categorycode => $patron_category, |
| 108 |
); |
100 |
itemtype => $item_type, |
|
|
101 |
branchcode => $branchcode, |
| 102 |
rules => $rules |
| 103 |
} |
| 104 |
); |
| 105 |
|
| 106 |
return $c->render( |
| 107 |
status => 200, |
| 108 |
openapi => $effective_rules ? $effective_rules : {} |
| 109 |
); |
| 110 |
} catch { |
| 111 |
$c->unhandled_exception($_); |
| 112 |
}; |
| 109 |
} |
113 |
} |
| 110 |
|
114 |
|
| 111 |
1; |
115 |
1; |