|
Lines 270-275
sub delete {
Link Here
|
| 270 |
return $c->render( status => 200, openapi => {} ); |
270 |
return $c->render( status => 200, openapi => {} ); |
| 271 |
} |
271 |
} |
| 272 |
|
272 |
|
|
|
273 |
=head3 suspend |
| 274 |
|
| 275 |
Method that handles suspending a hold |
| 276 |
|
| 277 |
=cut |
| 278 |
|
| 279 |
sub suspend { |
| 280 |
my $c = shift->openapi->valid_input or return; |
| 281 |
|
| 282 |
my $hold_id = $c->validation->param('hold_id'); |
| 283 |
my $hold = Koha::Holds->find($hold_id); |
| 284 |
my $body = $c->req->json; |
| 285 |
my $exp_date = ($body) ? $body->{expiration_date} : undef; |
| 286 |
|
| 287 |
unless ($hold) { |
| 288 |
return $c->render( status => 404, openapi => { error => 'Hold not found.' } ); |
| 289 |
} |
| 290 |
|
| 291 |
return try { |
| 292 |
my $date = ($exp_date) ? dt_from_string( $exp_date, 'rfc3339' ) : undef; |
| 293 |
$hold->suspend_hold($date); |
| 294 |
$hold->discard_changes; |
| 295 |
$c->res->headers->location( $c->req->url->to_string ); |
| 296 |
return $c->render( |
| 297 |
status => 201, |
| 298 |
openapi => { |
| 299 |
expiration_date => output_pref( |
| 300 |
{ dt => dt_from_string( $hold->suspend_until ), |
| 301 |
dateformat => 'rfc3339', |
| 302 |
dateonly => 1 |
| 303 |
} |
| 304 |
) |
| 305 |
} |
| 306 |
); |
| 307 |
} |
| 308 |
catch { |
| 309 |
if ( blessed $_ and $_->isa('Koha::Exceptions::Hold::CannotSuspendFound') ) { |
| 310 |
return $c->render( status => 400, openapi => { error => "$_" } ); |
| 311 |
} |
| 312 |
else { |
| 313 |
return $c->render( |
| 314 |
status => 500, |
| 315 |
openapi => { error => "Something went wrong. check the logs." } |
| 316 |
); |
| 317 |
} |
| 318 |
}; |
| 319 |
} |
| 320 |
|
| 321 |
=head3 resume |
| 322 |
|
| 323 |
Method that handles resuming a hold |
| 324 |
|
| 325 |
=cut |
| 326 |
|
| 327 |
sub resume { |
| 328 |
my $c = shift->openapi->valid_input or return; |
| 329 |
|
| 330 |
my $hold_id = $c->validation->param('hold_id'); |
| 331 |
my $hold = Koha::Holds->find($hold_id); |
| 332 |
my $body = $c->req->json; |
| 333 |
|
| 334 |
unless ($hold) { |
| 335 |
return $c->render( status => 404, openapi => { error => 'Hold not found.' } ); |
| 336 |
} |
| 337 |
|
| 338 |
return try { |
| 339 |
$hold->resume; |
| 340 |
return $c->render( status => 204, openapi => {} ); |
| 341 |
} |
| 342 |
catch { |
| 343 |
return $c->render( |
| 344 |
status => 500, |
| 345 |
openapi => { error => "Something went wrong. check the logs." } |
| 346 |
); |
| 347 |
}; |
| 348 |
} |
| 273 |
|
349 |
|
| 274 |
=head3 _to_api |
350 |
=head3 _to_api |
| 275 |
|
351 |
|
| 276 |
- |
|
|