Bugzilla – Attachment 118173 Details for
Bug 27932
Add GET /biblios/:biblio_id/pickup_locations
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27932: Add GET /biblios/:biblio_id/pickup_locations route
Bug-27932-Add-GET-bibliosbiblioidpickuplocations-r.patch (text/plain), 6.62 KB, created by
Tomás Cohen Arazi (tcohen)
on 2021-03-11 19:40:07 UTC
(
hide
)
Description:
Bug 27932: Add GET /biblios/:biblio_id/pickup_locations route
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2021-03-11 19:40:07 UTC
Size:
6.62 KB
patch
obsolete
>From 772891a0cf4db51f822f1c7d02c387c5a37d7443 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 11 Mar 2021 15:47:10 -0300 >Subject: [PATCH] Bug 27932: Add GET /biblios/:biblio_id/pickup_locations route > >This patch adds the mentioned route. It does so by: >- Adding the new path in paths.json >- Adding the full route spec in biblios.json >- Adds a controller method that takes care of the task > >To test: >1. Apply this patches >2. Run: > $ kshell > k$ prove t/db_dependent/api/v1/biblios.t >=> SUCCESS: Tests pass! >3. Play with your favourite REST tool. Pay special care to > the AllowHoldPolicyOverride syspref and the expected behaviors. >=> SUCCESS: All works as expected >4. Sign off :-D >--- > Koha/REST/V1/Biblios.pm | 72 +++++++++++++++++++++ > api/v1/swagger/paths.json | 3 + > api/v1/swagger/paths/biblios.json | 101 ++++++++++++++++++++++++++++++ > 3 files changed, 176 insertions(+) > >diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm >index efe7c5dfe8b..aa44f30e648 100644 >--- a/Koha/REST/V1/Biblios.pm >+++ b/Koha/REST/V1/Biblios.pm >@@ -23,6 +23,7 @@ use Koha::Biblios; > use Koha::RecordProcessor; > use C4::Biblio qw(DelBiblio); > >+use List::MoreUtils qw(any); > use MARC::Record::MiJ; > > use Try::Tiny; >@@ -268,4 +269,75 @@ sub get_items { > }; > } > >+=head3 pickup_locations >+ >+Method that returns the possible pickup_locations for a given biblio >+used for building the dropdown selector >+ >+=cut >+ >+sub pickup_locations { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $biblio_id = $c->validation->param('biblio_id'); >+ my $biblio = Koha::Biblios->find( $biblio_id ); >+ >+ unless ($biblio) { >+ return $c->render( >+ status => 404, >+ openapi => { error => "Biblio not found" } >+ ); >+ } >+ >+ my $patron_id = delete $c->validation->output->{patron_id}; >+ my $patron = Koha::Patrons->find( $patron_id ); >+ >+ unless ($patron) { >+ return $c->render( >+ status => 400, >+ openapi => { error => "Patron not found" } >+ ); >+ } >+ >+ return try { >+ >+ my $ps_set = $biblio->pickup_locations( { patron => $patron } ); >+ >+ my $pickup_locations = $c->objects->search( $ps_set ); >+ my @response = (); >+ >+ if ( C4::Context->preference('AllowHoldPolicyOverride') ) { >+ >+ my $libraries_rs = Koha::Libraries->search( { pickup_location => 1 } ); >+ my $libraries = $c->objects->search($libraries_rs); >+ >+ @response = map { >+ my $library = $_; >+ $library->{needs_override} = ( >+ any { $_->{library_id} eq $library->{library_id} } >+ @{$pickup_locations} >+ ) >+ ? Mojo::JSON->false >+ : Mojo::JSON->true; >+ $library; >+ } @{$libraries}; >+ >+ return $c->render( >+ status => 200, >+ openapi => \@response >+ ); >+ } >+ >+ @response = map { $_->{needs_override} = Mojo::JSON->false; $_; } @{$pickup_locations}; >+ >+ return $c->render( >+ status => 200, >+ openapi => \@response >+ ); >+ } >+ catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ > 1; >diff --git a/api/v1/swagger/paths.json b/api/v1/swagger/paths.json >index ae1ccc97993..33a3d04b620 100644 >--- a/api/v1/swagger/paths.json >+++ b/api/v1/swagger/paths.json >@@ -23,6 +23,9 @@ > "/biblios/{biblio_id}/items": { > "$ref": "paths/biblios.json#/~1biblios~1{biblio_id}~1items" > }, >+ "/biblios/{biblio_id}/pickup_locations": { >+ "$ref": "paths/biblios.json#/~1biblios~1{biblio_id}~1pickup_locations" >+ }, > "/cash_registers/{cash_register_id}/cashups": { > "$ref": "paths/cash_registers.json#/~1cash_registers~1{cash_register_id}~1cashups" > }, >diff --git a/api/v1/swagger/paths/biblios.json b/api/v1/swagger/paths/biblios.json >index 0b95576204d..9781202c593 100644 >--- a/api/v1/swagger/paths/biblios.json >+++ b/api/v1/swagger/paths/biblios.json >@@ -232,6 +232,107 @@ > } > } > }, >+ "/biblios/{biblio_id}/pickup_locations": { >+ "get": { >+ "x-mojo-to": "Biblios#pickup_locations", >+ "operationId": "getBiblioPickupLocations", >+ "tags": [ >+ "biblios", >+ "pickup_locations" >+ ], >+ "parameters": [ >+ { >+ "$ref": "../parameters.json#/biblio_id_pp" >+ }, >+ { >+ "name": "patron_id", >+ "in": "query", >+ "description": "Internal patron identifier", >+ "required": true, >+ "type": "integer" >+ }, >+ { >+ "$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": "Biblio pickup locations", >+ "schema": { >+ "type": "array", >+ "items": { >+ "$ref": "../definitions.json#/library" >+ } >+ } >+ }, >+ "400": { >+ "description": "Missing or wrong parameters", >+ "schema": { >+ "$ref": "../definitions.json#/error" >+ } >+ }, >+ "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" >+ } >+ }, >+ "500": { >+ "description": "Internal server error", >+ "schema": { >+ "$ref": "../definitions.json#/error" >+ } >+ }, >+ "503": { >+ "description": "Under maintenance", >+ "schema": { >+ "$ref": "../definitions.json#/error" >+ } >+ } >+ }, >+ "x-koha-authorization": { >+ "permissions": { >+ "reserveforothers": "place_holds" >+ } >+ } >+ } >+ }, > "/public/biblios/{biblio_id}": { > "get": { > "x-mojo-to": "Biblios#get_public", >-- >2.30.2
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 27932
:
118168
|
118169
|
118172
|
118173
|
118216
|
119715
|
119716