Bugzilla – Attachment 126156 Details for
Bug 27358
Add GET /public/biblios/:biblio_id/items
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27358: Add GET /public/biblios/:biblio_id/items
Bug-27358-Add-GET-publicbibliosbiblioiditems.patch (text/plain), 5.06 KB, created by
Martin Renvoize (ashimema)
on 2021-10-13 09:13:06 UTC
(
hide
)
Description:
Bug 27358: Add GET /public/biblios/:biblio_id/items
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2021-10-13 09:13:06 UTC
Size:
5.06 KB
patch
obsolete
>From ed49beb3a5ac90a3b2d04f8eec75be5d302e1d78 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 7 Jan 2021 08:50:43 -0300 >Subject: [PATCH] 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> >--- > Koha/REST/V1/Biblios.pm | 37 ++++++++++++ > api/v1/swagger/paths.json | 3 + > api/v1/swagger/paths/biblios.json | 93 +++++++++++++++++++++++++++++++ > 3 files changed, 133 insertions(+) > >diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm >index 3ddb896e73..1ac6ccdcfe 100644 >--- a/Koha/REST/V1/Biblios.pm >+++ b/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; >diff --git a/api/v1/swagger/paths.json b/api/v1/swagger/paths.json >index 298b411054..4b516a0886 100644 >--- a/api/v1/swagger/paths.json >+++ b/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" > }, >diff --git a/api/v1/swagger/paths/biblios.json b/api/v1/swagger/paths/biblios.json >index f1b494ddb1..03ef619393 100644 >--- a/api/v1/swagger/paths/biblios.json >+++ b/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" >+ } >+ } >+ } >+ } > } > } >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 27358
:
114922
|
114935
|
114936
|
114937
|
114938
|
114939
|
116187
|
116188
|
116189
|
116190
|
116191
|
123843
|
123844
|
123845
|
123846
|
123847
|
124454
|
124455
|
124456
|
124457
|
124458
|
124459
|
126156
|
126157
|
126158
|
126159
|
126164
|
126165
|
126971
|
126972