View | Details | Raw Unified | Return to bug 22206
Collapse All | Expand All

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

Return to bug 22206