Bug 27358: Add GET /public/biblios/:biblio_id/items
This patch introduces a route to fetch items belonging to a biblio. It is expected to return the 'public' representation of the Koha::Item objects. It is also enforcing the visibility rules, by using Koha::Items->filter_by_visible_in_opac. To test: 1. Apply this patches 2. Run: $ kshell k$ prove t/db_dependent/api/v1/biblios.t => SUCCESS: Test pass and they cover all the cases! 3. Try your favourite REST tool against the new route. 4. Sign off :-D Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
f907070116
commit
9ef23bb642
18
Koha/Item.pm
18
Koha/Item.pm
|
|
@ -1219,6 +1219,24 @@ sub _set_found_trigger {
|
|||
return $self;
|
||||
}
|
||||
|
||||
=head3 public_read_list
|
||||
|
||||
This method returns the list of publicly readable database fields for both API and UI output purposes
|
||||
|
||||
=cut
|
||||
|
||||
sub public_read_list {
|
||||
return [
|
||||
'itemnumber', 'biblionumber', 'homebranch',
|
||||
'holdingbranch', 'location', 'collectioncode',
|
||||
'itemcallnumber', 'copynumber', 'enumchron',
|
||||
'barcode', 'dateaccessioned', 'itemnotes',
|
||||
'onloan', 'uri', 'itype',
|
||||
'notforloan', 'damaged', 'itemlost',
|
||||
'withdrawn', 'restricted'
|
||||
];
|
||||
}
|
||||
|
||||
=head3 to_api_mapping
|
||||
|
||||
This method returns the mapping for representing a Koha::Item object
|
||||
|
|
|
|||
|
|
@ -340,4 +340,41 @@ sub pickup_locations {
|
|||
};
|
||||
}
|
||||
|
||||
=head3 get_items_public
|
||||
|
||||
Controller function that handles retrieving biblio's items, for unprivileged
|
||||
access.
|
||||
|
||||
=cut
|
||||
|
||||
sub get_items_public {
|
||||
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 $patron = $c->stash('koha.user');
|
||||
|
||||
my $items_rs = $biblio->items->filter_by_visible_in_opac({ patron => $patron });
|
||||
my $items = $c->objects->search( $items_rs );
|
||||
return $c->render(
|
||||
status => 200,
|
||||
openapi => $items
|
||||
);
|
||||
}
|
||||
catch {
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -164,6 +164,9 @@
|
|||
"/public/biblios/{biblio_id}": {
|
||||
"$ref": "paths/biblios.json#/~1public~1biblios~1{biblio_id}"
|
||||
},
|
||||
"/public/biblios/{biblio_id}/items": {
|
||||
"$ref": "paths/biblios.json#/~1public~1biblios~1{biblio_id}~1items"
|
||||
},
|
||||
"/public/libraries": {
|
||||
"$ref": "paths/libraries.json#/~1public~1libraries"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -396,5 +396,98 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/public/biblios/{biblio_id}/items": {
|
||||
"get": {
|
||||
"x-mojo-to": "Biblios#get_items_public",
|
||||
"operationId": "getBiblioItemsPublic",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue