From 8fdd52b17cfe149c5e9721161cab60e61ad97877 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 20 Oct 2021 18:12:41 -0300 Subject: [PATCH] Bug 29290: Add GET /biblios/:biblio_id/checkouts This patch adds the required controller method. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- Koha/REST/V1/Biblios.pm | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm index 1ac6ccdcfe..839d117f56 100644 --- a/Koha/REST/V1/Biblios.pm +++ b/Koha/REST/V1/Biblios.pm @@ -269,6 +269,42 @@ sub get_items { }; } +=head3 get_checkouts + +List Koha::Checkout objects + +=cut + +sub get_checkouts { + my $c = shift->openapi->valid_input or return; + + my $checked_in = delete $c->validation->output->{checked_in}; + + try { + my $biblio = Koha::Biblios->find( $c->validation->param('biblio_id') ); + + unless ($biblio) { + return $c->render( + status => 404, + openapi => { error => 'Object not found' } + ); + } + + my $checkouts = + ($checked_in) + ? $c->objects->search( scalar $biblio->old_checkouts ) + : $c->objects->search( scalar $biblio->current_checkouts ); + + return $c->render( + status => 200, + openapi => $checkouts + ); + } + catch { + $c->unhandled_exception($_); + }; +} + =head3 pickup_locations Method that returns the possible pickup_locations for a given biblio -- 2.39.5