@@ -, +, @@ $ kshell k$ prove t/db_dependent/api/v1/biblios.t --- Koha/Item.pm | 30 ++++++++++ Koha/REST/V1/Biblios.pm | 37 ++++++++++++ api/v1/swagger/paths.json | 3 + api/v1/swagger/paths/biblios.json | 93 +++++++++++++++++++++++++++++++ 4 files changed, 163 insertions(+) --- a/Koha/Item.pm +++ a/Koha/Item.pm @@ -1183,6 +1183,36 @@ 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', + 'barcode', 'dateaccessioned', + 'booksellerid', 'homebranch', + 'price', 'replacementprice', + 'replacementpricedate', 'datelastborrowed', + 'datelastseen', 'stack', + 'notforloan', 'damaged', + 'damaged_on', 'itemlost', + 'itemlost_on', 'withdrawn', + 'withdrawn_on', 'itemcallnumber', + 'coded_location_qualifier', 'renewals', + 'restricted', 'itemnotes', + 'holdingbranch', 'timestamp', + 'location', 'permanent_location', + 'cn_source', 'cn_sort', + 'ccode', 'materials', + 'uri', 'itype', + 'enumchron', 'copynumber', + 'stocknumber', 'new_status' + ]; +} + =head3 to_api_mapping This method returns the mapping for representing a Koha::Item object --- a/Koha/REST/V1/Biblios.pm +++ a/Koha/REST/V1/Biblios.pm @@ -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; --- a/api/v1/swagger/paths.json +++ a/api/v1/swagger/paths.json @@ -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" }, --- a/api/v1/swagger/paths/biblios.json +++ a/api/v1/swagger/paths/biblios.json @@ -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" + } + } + } + } } } --