|
Lines 27-45
use List::MoreUtils qw( any );
Link Here
|
| 27 |
use Try::Tiny qw( catch try ); |
27 |
use Try::Tiny qw( catch try ); |
| 28 |
|
28 |
|
| 29 |
=head1 NAME |
29 |
=head1 NAME |
| 30 |
|
|
|
| 31 |
Koha::REST::V1::Items - Koha REST API for handling items (V1) |
30 |
Koha::REST::V1::Items - Koha REST API for handling items (V1) |
| 32 |
|
|
|
| 33 |
=head1 API |
31 |
=head1 API |
| 34 |
|
|
|
| 35 |
=head2 Methods |
32 |
=head2 Methods |
| 36 |
|
|
|
| 37 |
=cut |
33 |
=cut |
| 38 |
|
34 |
|
| 39 |
=head3 list |
35 |
=head3 list |
| 40 |
|
|
|
| 41 |
Controller function that handles listing Koha::Item objects |
36 |
Controller function that handles listing Koha::Item objects |
| 42 |
|
|
|
| 43 |
=cut |
37 |
=cut |
| 44 |
|
38 |
|
| 45 |
sub list { |
39 |
sub list { |
|
Lines 59-67
sub list {
Link Here
|
| 59 |
} |
53 |
} |
| 60 |
|
54 |
|
| 61 |
=head3 list_public |
55 |
=head3 list_public |
| 62 |
|
|
|
| 63 |
Controller function that handles listing Koha::Item objects available to the opac |
56 |
Controller function that handles listing Koha::Item objects available to the opac |
| 64 |
|
|
|
| 65 |
=cut |
57 |
=cut |
| 66 |
|
58 |
|
| 67 |
sub list_public { |
59 |
sub list_public { |
|
Lines 85-93
sub list_public {
Link Here
|
| 85 |
} |
77 |
} |
| 86 |
|
78 |
|
| 87 |
=head3 get |
79 |
=head3 get |
| 88 |
|
|
|
| 89 |
Controller function that handles retrieving a single Koha::Item |
80 |
Controller function that handles retrieving a single Koha::Item |
| 90 |
|
|
|
| 91 |
=cut |
81 |
=cut |
| 92 |
|
82 |
|
| 93 |
sub get { |
83 |
sub get { |
|
Lines 110-118
sub get {
Link Here
|
| 110 |
} |
100 |
} |
| 111 |
|
101 |
|
| 112 |
=head3 delete |
102 |
=head3 delete |
| 113 |
|
|
|
| 114 |
Controller function that handles deleting a single Koha::Item |
103 |
Controller function that handles deleting a single Koha::Item |
| 115 |
|
|
|
| 116 |
=cut |
104 |
=cut |
| 117 |
|
105 |
|
| 118 |
sub delete { |
106 |
sub delete { |
|
Lines 173-184
sub delete {
Link Here
|
| 173 |
$c->unhandled_exception($_); |
161 |
$c->unhandled_exception($_); |
| 174 |
}; |
162 |
}; |
| 175 |
} |
163 |
} |
|
|
164 |
=head3 checkout |
| 165 |
|
| 166 |
Check out an item |
| 167 |
|
| 168 |
=cut |
| 169 |
|
| 170 |
sub checkout { |
| 171 |
my $c = shift->openapi->valid_input or return; |
| 172 |
my $item_id = $c->validation->param('item_id'); |
| 173 |
my $item = Koha::Items->find( $item_id ); |
| 174 |
unless ( $item ) { |
| 175 |
return $c->render( |
| 176 |
status => 404, |
| 177 |
openapi => { error => "Item not found" } |
| 178 |
); |
| 179 |
} |
| 180 |
my $patron_id = $c->validation->param('patron_id'); |
| 181 |
my $patron = Koha::Patrons->find( $patron_id ); |
| 182 |
unless ( $patron ) { |
| 183 |
return $c->render( |
| 184 |
status => 400, |
| 185 |
openapi => { error => "Patron not found" } |
| 186 |
); |
| 187 |
} |
| 188 |
try { |
| 189 |
my $barcode = $item->barcode; |
| 190 |
my ( $issuing_impossible, $needs_confirmation ) = C4::Circulation::CanBookBeIssued( $patron, $barcode ); |
| 191 |
if ( keys %$issuing_impossible or keys %$needs_confirmation ) { |
| 192 |
return $c->render( |
| 193 |
status => 403, |
| 194 |
openapi => { error => "Checkout not allowed" } |
| 195 |
); |
| 196 |
} |
| 197 |
my $borrower = $patron->unblessed; |
| 198 |
my $checkout = C4::Circulation::AddIssue( |
| 199 |
$borrower, |
| 200 |
$barcode |
| 201 |
); |
| 202 |
|
| 203 |
$c->res->headers->location( $c->req->url->to_string ); |
| 204 |
return $c->render( |
| 205 |
status => 201, |
| 206 |
openapi => $checkout->to_api |
| 207 |
); |
| 208 |
} |
| 209 |
catch { |
| 210 |
$c->unhandled_exception($_); |
| 211 |
}; |
| 212 |
} |
| 176 |
|
213 |
|
| 177 |
=head3 pickup_locations |
214 |
=head3 pickup_locations |
| 178 |
|
|
|
| 179 |
Method that returns the possible pickup_locations for a given item |
215 |
Method that returns the possible pickup_locations for a given item |
| 180 |
used for building the dropdown selector |
216 |
used for building the dropdown selector |
| 181 |
|
|
|
| 182 |
=cut |
217 |
=cut |
| 183 |
|
218 |
|
| 184 |
sub pickup_locations { |
219 |
sub pickup_locations { |
|
Lines 242-250
sub pickup_locations {
Link Here
|
| 242 |
} |
277 |
} |
| 243 |
|
278 |
|
| 244 |
=head3 bundled_items |
279 |
=head3 bundled_items |
| 245 |
|
|
|
| 246 |
Controller function that handles bundled_items Koha::Item objects |
280 |
Controller function that handles bundled_items Koha::Item objects |
| 247 |
|
|
|
| 248 |
=cut |
281 |
=cut |
| 249 |
|
282 |
|
| 250 |
sub bundled_items { |
283 |
sub bundled_items { |
|
Lines 274-282
sub bundled_items {
Link Here
|
| 274 |
} |
307 |
} |
| 275 |
|
308 |
|
| 276 |
=head3 add_to_bundle |
309 |
=head3 add_to_bundle |
| 277 |
|
|
|
| 278 |
Controller function that handles adding items to this bundle |
310 |
Controller function that handles adding items to this bundle |
| 279 |
|
|
|
| 280 |
=cut |
311 |
=cut |
| 281 |
|
312 |
|
| 282 |
sub add_to_bundle { |
313 |
sub add_to_bundle { |
|
Lines 371-379
sub add_to_bundle {
Link Here
|
| 371 |
} |
402 |
} |
| 372 |
|
403 |
|
| 373 |
=head3 remove_from_bundle |
404 |
=head3 remove_from_bundle |
| 374 |
|
|
|
| 375 |
Controller function that handles removing items from this bundle |
405 |
Controller function that handles removing items from this bundle |
| 376 |
|
|
|
| 377 |
=cut |
406 |
=cut |
| 378 |
|
407 |
|
| 379 |
sub remove_from_bundle { |
408 |
sub remove_from_bundle { |
|
Lines 408-410
sub remove_from_bundle {
Link Here
|
| 408 |
} |
437 |
} |
| 409 |
|
438 |
|
| 410 |
1; |
439 |
1; |
|
|
440 |
|
| 441 |
|