From 0f11d6acbb5d61c8b8fafd845eb8de650a84a201 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 6 Jan 2021 12:00:40 -0300 Subject: [PATCH] Bug 27352: Add GET /biblios/:biblio_id/items This patch adds a route to fetch the items for a biblio. It relies entirely on already existing methods. To test: 1. Use your favourite REST tool 2. Play with the new route. => SUCCESS: It works as expected! Signed-off-by: Tomas Cohen Arazi Signed-off-by: Lucas Gass Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- Koha/REST/V1/Biblios.pm | 34 +++++++++++ api/v1/swagger/paths.json | 9 ++- api/v1/swagger/paths/biblios.json | 98 +++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 3 deletions(-) diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm index 157282b4a1..4e803b1988 100644 --- a/Koha/REST/V1/Biblios.pm +++ b/Koha/REST/V1/Biblios.pm @@ -237,4 +237,38 @@ sub get_public { }; } +=head3 get_items + +Controller function that handles retrieving biblio's items + +=cut + +sub get_items { + my $c = shift->openapi->valid_input or return; + + my $biblio = Koha::Biblios->find( { biblionumber => $c->validation->param('biblio_id') }, { prefetch => ['items'] } ); + + unless ( $biblio ) { + return $c->render( + status => 404, + openapi => { + error => "Object not found." + } + ); + } + + return try { + + my $items_rs = $biblio->items; + my $items = $c->objects->search( $items_rs ); + return $c->render( + status => 200, + openapi => $items + ); + } + catch { + $c->unhandled_exception($_); + }; +} + 1; diff --git a/api/v1/swagger/paths.json b/api/v1/swagger/paths.json index 3b5dc352d5..e871e54ed4 100644 --- a/api/v1/swagger/paths.json +++ b/api/v1/swagger/paths.json @@ -17,6 +17,12 @@ "/acquisitions/funds": { "$ref": "paths/acquisitions_funds.json#/~1acquisitions~1funds" }, + "/biblios/{biblio_id}": { + "$ref": "paths/biblios.json#/~1biblios~1{biblio_id}" + }, + "/biblios/{biblio_id}/items": { + "$ref": "paths/biblios.json#/~1biblios~1{biblio_id}~1items" + }, "/checkouts": { "$ref": "paths/checkouts.json#/~1checkouts" }, @@ -35,9 +41,6 @@ "/cities/{city_id}": { "$ref": "paths/cities.json#/~1cities~1{city_id}" }, - "/biblios/{biblio_id}": { - "$ref": "paths/biblios.json#/~1biblios~1{biblio_id}" - }, "/clubs/{club_id}/holds": { "$ref": "paths/clubs.json#/~1clubs~1{club_id}~1holds" }, diff --git a/api/v1/swagger/paths/biblios.json b/api/v1/swagger/paths/biblios.json index 4896b71f62..0b95576204 100644 --- a/api/v1/swagger/paths/biblios.json +++ b/api/v1/swagger/paths/biblios.json @@ -134,6 +134,104 @@ } } }, + "/biblios/{biblio_id}/items": { + "get": { + "x-mojo-to": "Biblios#get_items", + "operationId": "getBiblioItems", + "tags": [ + "biblios", + "items" + ], + "parameters": [ + { + "$ref": "../parameters.json#/biblio_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" + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "A list of the items attached to the record", + "schema": { + "type": "array", + "items": { + "$ref": "../definitions.json#/item" + } + } + }, + "401": { + "description": "Authentication required", + "schema": { + "$ref": "../definitions.json#/error" + } + }, + "403": { + "description": "Access forbidden", + "schema": { + "$ref": "../definitions.json#/error" + } + }, + "404": { + "description": "Biblio not found", + "schema": { + "$ref": "../definitions.json#/error" + } + }, + "406": { + "description": "Not acceptable", + "schema": { + "type": "array", + "description": "Accepted content-types", + "items": { + "type": "string" + } + } + }, + "500": { + "description": "Internal server error", + "schema": { + "$ref": "../definitions.json#/error" + } + }, + "503": { + "description": "Under maintenance", + "schema": { + "$ref": "../definitions.json#/error" + } + } + }, + "x-koha-authorization": { + "permissions": { + "catalogue": "1" + } + } + } + }, "/public/biblios/{biblio_id}": { "get": { "x-mojo-to": "Biblios#get_public", -- 2.39.5