Lines 58-64
sub get {
Link Here
|
58 |
my $c = shift->openapi->valid_input or return; |
58 |
my $c = shift->openapi->valid_input or return; |
59 |
|
59 |
|
60 |
return try { |
60 |
return try { |
61 |
my $train_id = $c->validation->param('train_id'); |
61 |
my $train_id = $c->param('train_id'); |
62 |
my $train = $c->objects->find( Koha::Preservation::Trains->search, $train_id ); |
62 |
my $train = $c->objects->find( Koha::Preservation::Trains->search, $train_id ); |
63 |
|
63 |
|
64 |
unless ($train) { |
64 |
unless ($train) { |
Lines 91-97
sub add {
Link Here
|
91 |
Koha::Database->new->schema->txn_do( |
91 |
Koha::Database->new->schema->txn_do( |
92 |
sub { |
92 |
sub { |
93 |
|
93 |
|
94 |
my $body = $c->validation->param('body'); |
94 |
my $body = $c->req->json; |
95 |
|
95 |
|
96 |
my $train = Koha::Preservation::Train->new_from_api($body)->store; |
96 |
my $train = Koha::Preservation::Train->new_from_api($body)->store; |
97 |
|
97 |
|
Lines 155-161
Controller function that handles updating a Koha::Preservation::Train object
Link Here
|
155 |
sub update { |
155 |
sub update { |
156 |
my $c = shift->openapi->valid_input or return; |
156 |
my $c = shift->openapi->valid_input or return; |
157 |
|
157 |
|
158 |
my $train_id = $c->validation->param('train_id'); |
158 |
my $train_id = $c->param('train_id'); |
159 |
my $train = Koha::Preservation::Trains->find( $train_id ); |
159 |
my $train = Koha::Preservation::Trains->find( $train_id ); |
160 |
|
160 |
|
161 |
unless ($train) { |
161 |
unless ($train) { |
Lines 169-175
sub update {
Link Here
|
169 |
Koha::Database->new->schema->txn_do( |
169 |
Koha::Database->new->schema->txn_do( |
170 |
sub { |
170 |
sub { |
171 |
|
171 |
|
172 |
my $body = $c->validation->param('body'); |
172 |
my $body = $c->req->json; |
173 |
|
173 |
|
174 |
$train->set_from_api($body)->store; |
174 |
$train->set_from_api($body)->store; |
175 |
|
175 |
|
Lines 226-232
Controller function that handles deleting a Koha::Preservation::Train object
Link Here
|
226 |
sub delete { |
226 |
sub delete { |
227 |
my $c = shift->openapi->valid_input or return; |
227 |
my $c = shift->openapi->valid_input or return; |
228 |
|
228 |
|
229 |
my $train = Koha::Preservation::Trains->find( $c->validation->param('train_id') ); |
229 |
my $train = Koha::Preservation::Trains->find( $c->param('train_id') ); |
230 |
unless ($train) { |
230 |
unless ($train) { |
231 |
return $c->render( |
231 |
return $c->render( |
232 |
status => 404, |
232 |
status => 404, |
Lines 255-261
Controller function that handles getting an item from a train
Link Here
|
255 |
sub get_item { |
255 |
sub get_item { |
256 |
my $c = shift->openapi->valid_input or return; |
256 |
my $c = shift->openapi->valid_input or return; |
257 |
|
257 |
|
258 |
my $train_id = $c->validation->param('train_id'); |
258 |
my $train_id = $c->param('train_id'); |
259 |
my $train = Koha::Preservation::Trains->find( $train_id ); |
259 |
my $train = Koha::Preservation::Trains->find( $train_id ); |
260 |
|
260 |
|
261 |
unless ($train) { |
261 |
unless ($train) { |
Lines 265-271
sub get_item {
Link Here
|
265 |
); |
265 |
); |
266 |
} |
266 |
} |
267 |
|
267 |
|
268 |
my $train_item_id = $c->validation->param('train_item_id'); |
268 |
my $train_item_id = $c->param('train_item_id'); |
269 |
|
269 |
|
270 |
my $train_item = $c->objects->find(Koha::Preservation::Train::Items->search, { train_item_id => $train_item_id, train_id => $train_id }); |
270 |
my $train_item = $c->objects->find(Koha::Preservation::Train::Items->search, { train_item_id => $train_item_id, train_id => $train_id }); |
271 |
|
271 |
|
Lines 297-303
Controller function that handles adding items in batch to a train
Link Here
|
297 |
sub add_items { |
297 |
sub add_items { |
298 |
my $c = shift->openapi->valid_input or return; |
298 |
my $c = shift->openapi->valid_input or return; |
299 |
|
299 |
|
300 |
my $train_id = $c->validation->param('train_id'); |
300 |
my $train_id = $c->param('train_id'); |
301 |
my $train = Koha::Preservation::Trains->find( $train_id ); |
301 |
my $train = Koha::Preservation::Trains->find( $train_id ); |
302 |
|
302 |
|
303 |
unless ($train) { |
303 |
unless ($train) { |
Lines 307-313
sub add_items {
Link Here
|
307 |
); |
307 |
); |
308 |
} |
308 |
} |
309 |
|
309 |
|
310 |
my $body = $c->validation->every_param('body'); |
310 |
my $body = $c->req->json; |
311 |
return try { |
311 |
return try { |
312 |
Koha::Database->new->schema->txn_do( |
312 |
Koha::Database->new->schema->txn_do( |
313 |
sub { |
313 |
sub { |
Lines 339-345
Controller function that handles adding a new item to a train
Link Here
|
339 |
sub add_item { |
339 |
sub add_item { |
340 |
my $c = shift->openapi->valid_input or return; |
340 |
my $c = shift->openapi->valid_input or return; |
341 |
|
341 |
|
342 |
my $train_id = $c->validation->param('train_id'); |
342 |
my $train_id = $c->param('train_id'); |
343 |
my $train = Koha::Preservation::Trains->find( $train_id ); |
343 |
my $train = Koha::Preservation::Trains->find( $train_id ); |
344 |
|
344 |
|
345 |
unless ($train) { |
345 |
unless ($train) { |
Lines 349-355
sub add_item {
Link Here
|
349 |
); |
349 |
); |
350 |
} |
350 |
} |
351 |
|
351 |
|
352 |
my $body = $c->validation->param('body'); |
352 |
my $body = $c->req->json; |
353 |
return try { |
353 |
return try { |
354 |
Koha::Database->new->schema->txn_do( |
354 |
Koha::Database->new->schema->txn_do( |
355 |
sub { |
355 |
sub { |
Lines 408-414
Controller function that handles copying an item from a train to an other
Link Here
|
408 |
sub copy_item { |
408 |
sub copy_item { |
409 |
my $c = shift->openapi->valid_input or return; |
409 |
my $c = shift->openapi->valid_input or return; |
410 |
|
410 |
|
411 |
my $train_id = $c->validation->param('train_id'); |
411 |
my $train_id = $c->param('train_id'); |
412 |
my $train = Koha::Preservation::Trains->find( $train_id ); |
412 |
my $train = Koha::Preservation::Trains->find( $train_id ); |
413 |
|
413 |
|
414 |
unless ($train) { |
414 |
unless ($train) { |
Lines 418-424
sub copy_item {
Link Here
|
418 |
); |
418 |
); |
419 |
} |
419 |
} |
420 |
|
420 |
|
421 |
my $train_item_id = $c->validation->param('train_item_id'); |
421 |
my $train_item_id = $c->param('train_item_id'); |
422 |
|
422 |
|
423 |
my $train_item = Koha::Preservation::Train::Items->search({ train_item_id => $train_item_id, train_id => $train_id })->single; |
423 |
my $train_item = Koha::Preservation::Train::Items->search({ train_item_id => $train_item_id, train_id => $train_id })->single; |
424 |
|
424 |
|
Lines 429-435
sub copy_item {
Link Here
|
429 |
); |
429 |
); |
430 |
} |
430 |
} |
431 |
|
431 |
|
432 |
my $body = $c->validation->param('body'); |
432 |
my $body = $c->req->json; |
433 |
return try { |
433 |
return try { |
434 |
Koha::Database->new->schema->txn_do( |
434 |
Koha::Database->new->schema->txn_do( |
435 |
sub { |
435 |
sub { |
Lines 512-518
Controller function that handles updating an item from a train
Link Here
|
512 |
sub update_item { |
512 |
sub update_item { |
513 |
my $c = shift->openapi->valid_input or return; |
513 |
my $c = shift->openapi->valid_input or return; |
514 |
|
514 |
|
515 |
my $train_id = $c->validation->param('train_id'); |
515 |
my $train_id = $c->param('train_id'); |
516 |
my $train = Koha::Preservation::Trains->find( $train_id ); |
516 |
my $train = Koha::Preservation::Trains->find( $train_id ); |
517 |
|
517 |
|
518 |
unless ($train) { |
518 |
unless ($train) { |
Lines 522-528
sub update_item {
Link Here
|
522 |
); |
522 |
); |
523 |
} |
523 |
} |
524 |
|
524 |
|
525 |
my $train_item_id = $c->validation->param('train_item_id'); |
525 |
my $train_item_id = $c->param('train_item_id'); |
526 |
|
526 |
|
527 |
my $train_item = Koha::Preservation::Train::Items->search({ train_item_id => $train_item_id, train_id => $train_id })->single; |
527 |
my $train_item = Koha::Preservation::Train::Items->search({ train_item_id => $train_item_id, train_id => $train_id })->single; |
528 |
|
528 |
|
Lines 536-542
sub update_item {
Link Here
|
536 |
return try { |
536 |
return try { |
537 |
Koha::Database->new->schema->txn_do( |
537 |
Koha::Database->new->schema->txn_do( |
538 |
sub { |
538 |
sub { |
539 |
my $body = $c->validation->param('body'); |
539 |
my $body = $c->req->json; |
540 |
my $attributes = delete $body->{attributes} // []; |
540 |
my $attributes = delete $body->{attributes} // []; |
541 |
|
541 |
|
542 |
$train_item->set_from_api($body)->store; |
542 |
$train_item->set_from_api($body)->store; |
Lines 560-566
Controller function that handles removing an item from a train
Link Here
|
560 |
sub remove_item { |
560 |
sub remove_item { |
561 |
my $c = shift->openapi->valid_input or return; |
561 |
my $c = shift->openapi->valid_input or return; |
562 |
|
562 |
|
563 |
my $train_id = $c->validation->param('train_id'); |
563 |
my $train_id = $c->param('train_id'); |
564 |
my $train = Koha::Preservation::Trains->find( $train_id ); |
564 |
my $train = Koha::Preservation::Trains->find( $train_id ); |
565 |
|
565 |
|
566 |
unless ($train) { |
566 |
unless ($train) { |
Lines 570-576
sub remove_item {
Link Here
|
570 |
); |
570 |
); |
571 |
} |
571 |
} |
572 |
|
572 |
|
573 |
my $train_item_id = $c->validation->param('train_item_id'); |
573 |
my $train_item_id = $c->param('train_item_id'); |
574 |
|
574 |
|
575 |
my $train_item = $train->items->find($train_item_id); |
575 |
my $train_item = $train->items->find($train_item_id); |
576 |
|
576 |
|