From 22b314a97cc9e31372d632554354082e6b93f0c7 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 10 Nov 2020 17:38:26 -0300 Subject: [PATCH] Bug 26988: (QA follow-up) Make the API return proper library objects Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart (cherry picked from commit 14506040292201a78733a9c1746bf7f590205fe3) Signed-off-by: Andrew Fuerste-Henry --- Koha/REST/V1/Holds.pm | 16 +++++++++++----- api/v1/swagger/paths/holds.json | 8 +++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm index 2b325128bb..c32c2f8359 100644 --- a/Koha/REST/V1/Holds.pm +++ b/Koha/REST/V1/Holds.pm @@ -404,7 +404,7 @@ sub pickup_locations { my $c = shift->openapi->valid_input or return; my $hold_id = $c->validation->param('hold_id'); - my $hold = Koha::Holds->find($hold_id); + my $hold = Koha::Holds->find( $hold_id, { prefetch => [ 'patron' ] } ); unless ($hold) { return $c->render( @@ -414,11 +414,17 @@ sub pickup_locations { } return try { - my $pickup_locations = $hold->itemnumber ? - $hold->item->pickup_locations({ patron => $hold->patron }) : $hold->biblio->pickup_locations({ patron => $hold->patron }); - warn Data::Dumper::Dumper( $pickup_locations ); + my @pickup_locations = + $hold->itemnumber + ? @{ $hold->item->pickup_locations( { patron => $hold->patron } ) } + : @{ $hold->biblio->pickup_locations( { patron => $hold->patron } ) }; + + @pickup_locations = map { $_->to_api } @pickup_locations; - return $c->render( status => 200, openapi => $pickup_locations ); + return $c->render( + status => 200, + openapi => \@pickup_locations + ); } catch { $c->unhandled_exception($_); diff --git a/api/v1/swagger/paths/holds.json b/api/v1/swagger/paths/holds.json index 4721b1409c..7982be3e60 100644 --- a/api/v1/swagger/paths/holds.json +++ b/api/v1/swagger/paths/holds.json @@ -615,7 +615,13 @@ "produces": ["application/json"], "responses": { "200": { - "description": "Hold pickup location" + "description": "Hold pickup location", + "schema": { + "type": "array", + "items": { + "$ref": "../definitions.json#/library" + } + } }, "400": { "description": "Missing or wrong parameters", -- 2.39.5