Browse Source

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 <tomascohen@theke.io>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
21.05.x
Tomas Cohen Arazi 1 year ago
committed by Jonathan Druart
parent
commit
0f11d6acbb
  1. 34
      Koha/REST/V1/Biblios.pm
  2. 9
      api/v1/swagger/paths.json
  3. 98
      api/v1/swagger/paths/biblios.json

34
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;

9
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"
},

98
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",

Loading…
Cancel
Save