From a60c1b77f8d5175707afcafe543cda9d404b1883 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 13 Nov 2020 19:09:52 -0300 Subject: [PATCH] Bug 27015: Make pickup locations searchable Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Nind Signed-off-by: Nick Clemens Signed-off-by: Jonathan Druart --- Koha/REST/V1/Holds.pm | 18 ++++++++++++------ api/v1/swagger/paths/holds.json | 27 +++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm index 9e230fe4d0..ea233ffb32 100644 --- a/Koha/REST/V1/Holds.pm +++ b/Koha/REST/V1/Holds.pm @@ -445,6 +445,8 @@ sub pickup_locations { my $c = shift->openapi->valid_input or return; my $hold_id = $c->validation->param('hold_id'); + # FIXME: We should really skip the path params in $c->objects->search + delete $c->validation->output->{hold_id}; my $hold = Koha::Holds->find( $hold_id, { prefetch => [ 'patron' ] } ); unless ($hold) { @@ -455,16 +457,20 @@ sub pickup_locations { } return try { - my @pickup_locations = - $hold->itemnumber - ? @{ $hold->item->pickup_locations( { patron => $hold->patron } )->as_list() } - : @{ $hold->biblio->pickup_locations( { patron => $hold->patron } )->as_list() }; + my $ps_set; - @pickup_locations = map { $_->to_api } @pickup_locations; + if ( $hold->itemnumber ) { + $ps_set = $hold->item->pickup_locations( { patron => $hold->patron } ); + } + else { + $ps_set = $hold->biblio->pickup_locations( { patron => $hold->patron } ); + } + + my $pickup_locations = $c->objects->search( $ps_set ); return $c->render( status => 200, - openapi => \@pickup_locations + openapi => $pickup_locations ); } catch { diff --git a/api/v1/swagger/paths/holds.json b/api/v1/swagger/paths/holds.json index 386b4a9470..a578adb252 100644 --- a/api/v1/swagger/paths/holds.json +++ b/api/v1/swagger/paths/holds.json @@ -619,9 +619,32 @@ "x-mojo-to": "Holds#pickup_locations", "operationId": "getHoldPickupLocations", "tags": ["holds"], - "parameters": [{ + "parameters": [ + { "$ref": "../parameters.json#/hold_id_pp" - }], + }, + { + "$ref": "../parameters.json#/match" + }, + { + "$ref": "../parameters.json#/order_by" + }, + { + "$ref": "../parameters.json#/page" + }, + { + "$ref": "../parameters.json#/per_page" + }, + { + "$ref": "../parameters.json#/q_param" + }, + { + "$ref": "../parameters.json#/q_body" + }, + { + "$ref": "../parameters.json#/q_header" + } + ], "produces": ["application/json"], "responses": { "200": { -- 2.39.5