From 14ce95ccb1f1f7843c278a97c67ae4c6f755c6a1 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 --- 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 30579caa40..2eb85db95c 100644 --- a/Koha/REST/V1/Holds.pm +++ b/Koha/REST/V1/Holds.pm @@ -406,6 +406,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) { @@ -416,16 +418,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 3792985c8c..6bdcccc028 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.11.0