Bugzilla – Attachment 37365 Details for
Bug 13927
Add API route to check hold capabilities
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13927: Add API route to check hold capabilities
Bug-13927-Add-API-route-to-check-hold-capabilities.patch (text/plain), 4.72 KB, created by
Julian Maurice
on 2015-03-30 12:41:31 UTC
(
hide
)
Description:
Bug 13927: Add API route to check hold capabilities
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2015-03-30 12:41:31 UTC
Size:
4.72 KB
patch
obsolete
>From a80dc433771fac0aa8d16c9bace2f703105721fd Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Wed, 25 Mar 2015 17:03:45 +0100 >Subject: [PATCH] Bug 13927: Add API route to check hold capabilities > >OPTIONS /borrowers/{borrowernumber}/reserves > >Request body should contain biblionumber or itemnumber, and response >tells us if reserve is allowed, and which pickup locations are available >--- > Koha/REST/V1/Borrowers/Reserves.pm | 51 ++++++++++++++++++++++++++++++++++ > api/v1/swagger.json | 56 ++++++++++++++++++++++++++++++++++++++ > 2 files changed, 107 insertions(+) > >diff --git a/Koha/REST/V1/Borrowers/Reserves.pm b/Koha/REST/V1/Borrowers/Reserves.pm >index 4dca9b7..ef496fc 100644 >--- a/Koha/REST/V1/Borrowers/Reserves.pm >+++ b/Koha/REST/V1/Borrowers/Reserves.pm >@@ -8,6 +8,7 @@ use Koha::Borrowers; > use Koha::Borrower; > > use C4::Biblio; >+use C4::Branch; > use C4::Dates; > use C4::Reserves; > >@@ -96,4 +97,54 @@ sub add_borrower_reserve { > return $c->$cb($reserve, 201); > } > >+sub options_borrower_reserve { >+ my ($c, $args, $cb) = @_; >+ >+ my $borrowernumber = $args->{borrowernumber}; >+ my $borrower = Koha::Borrowers->find($borrowernumber); >+ unless ($borrower) { >+ return $c->$cb({error => "Borrower not found"}, 404); >+ } >+ >+ my $body = $c->req->json; >+ >+ my $biblionumber = $body->{biblionumber}; >+ my $itemnumber = $body->{itemnumber}; >+ >+ unless ($biblionumber or $itemnumber) { >+ return $c->$cb({ >+ error => "At least one of biblionumber, itemnumber should be given" >+ }, 400); >+ } >+ >+ if ($itemnumber) { >+ my $item_biblionumber = C4::Biblio::GetBiblionumberFromItemnumber($itemnumber); >+ if ($biblionumber and $biblionumber != $item_biblionumber) { >+ return $c->$cb({ >+ error => "Item $itemnumber doesn't belong to biblio $biblionumber" >+ }, 400); >+ } >+ $biblionumber ||= $item_biblionumber; >+ } >+ >+ my $biblio = C4::Biblio::GetBiblio($biblionumber); >+ >+ my $can_reserve = >+ $itemnumber >+ ? CanItemBeReserved( $borrowernumber, $itemnumber ) >+ : CanBookBeReserved( $borrowernumber, $biblionumber ); >+ >+ my @branches = values %{ C4::Branch::GetBranches() }; >+ if (C4::Context->preference('IndependentBranches')) { >+ @branches = grep { $_->{branchcode} eq $borrower->branchcode } @branches; >+ } >+ >+ my $response = { >+ reserve_allowed => $can_reserve eq 'OK' ? 1 : 0, >+ available_pickup_locations => \@branches, >+ }; >+ >+ return $c->$cb($response, 200); >+} >+ > 1; >diff --git a/api/v1/swagger.json b/api/v1/swagger.json >index 6a252a7..294640e 100644 >--- a/api/v1/swagger.json >+++ b/api/v1/swagger.json >@@ -122,6 +122,37 @@ > "schema": { "$ref": "#/definitions/error" } > } > } >+ }, >+ "options": { >+ "x-mojo-controller": "Koha::REST::V1::Borrowers::Reserves", >+ "operationId": "optionsBorrowerReserve", >+ "tags": ["borrowers", "reserves"], >+ "parameters": [ >+ { "$ref": "#/parameters/borrowernumberPathParam" }, >+ { >+ "name": "body", >+ "in": "body", >+ "description": "A JSON object to detail the request", >+ "required": true, >+ "schema": { "$ref": "#/definitions/optionsBorrowerReserveBody" } >+ } >+ ], >+ "consumes": ["application/json"], >+ "produces": ["application/json"], >+ "responses": { >+ "200": { >+ "description": "Available options for /borrowers/{borrowernumber}/reserves", >+ "schema": { "$ref": "#/definitions/borrowerReservesOptions" } >+ }, >+ "400": { >+ "description": "Bad parameters", >+ "schema": { "$ref": "#/definitions/error" } >+ }, >+ "404": { >+ "description": "Borrower not found", >+ "schema": { "$ref": "#/definitions/error" } >+ } >+ } > } > }, > "/reserves/{reserve_id}": { >@@ -278,6 +309,31 @@ > } > } > }, >+ "optionsBorrowerReserveBody": { >+ "type": "object", >+ "properties": { >+ "biblionumber": { >+ "description": "Biblio internal identifier", >+ "type": "integer" >+ }, >+ "itemnumber": { >+ "description": "Item internal identifier", >+ "type": "integer" >+ } >+ } >+ }, >+ "borrowerReservesOptions": { >+ "type": "object", >+ "properties": { >+ "reserve_allowed": { >+ "type": "integer" >+ }, >+ "available_pickup_locations": { >+ "type": "array", >+ "items": { "$ref": "#/definitions/branch" } >+ } >+ } >+ }, > "editReserveBody": { > "type": "object", > "properties": { >-- >1.9.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 13927
: 37365