Bugzilla – Attachment 60156 Details for
Bug 16826
REST API: Add API routes for getting item availability and holdability
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16826: Swaggerize Koha::Availability objects
Bug-16826-Swaggerize-KohaAvailability-objects.patch (text/plain), 5.99 KB, created by
Lari Taskula
on 2017-02-13 12:34:57 UTC
(
hide
)
Description:
Bug 16826: Swaggerize Koha::Availability objects
Filename:
MIME Type:
Creator:
Lari Taskula
Created:
2017-02-13 12:34:57 UTC
Size:
5.99 KB
patch
obsolete
>From f249688350651c1a611e8d71ca8aa1d5247a437f Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@jns.fi> >Date: Mon, 19 Dec 2016 14:11:45 +0200 >Subject: [PATCH] Bug 16826: Swaggerize Koha::Availability objects > >Koha::Biblio::Availability->swaggerize >Koha::Item::Availability->swaggerize > >Constructs a HASHref that contains all availability data to be returned in a JSON >object. Numifies numbers to be numbers instead of strings. E.g. biblio swaggerize > >{ > "biblionumber": 1234, > "availability": { > "available": true, > "notes": { > "Patron::SomethingToNote": { > "cool": 1 > } > } > }, > "item_availabilities": [ > { > "itemnumber": 5678, > "availability": { > "available": false, > "unavailabilities": { > "Item::Withdrawn": {} > } > } > } > ] >} >--- > Koha/Availability.pm | 16 ++++++++++++ > Koha/Biblio/Availability.pm | 46 ++++++++++++++++++++++++++++++++++ > Koha/Item/Availability.pm | 45 +++++++++++++++++++++++++++++++++ > api/v1/swagger/paths/availability.json | 9 ++++++- > 4 files changed, 115 insertions(+), 1 deletion(-) > >diff --git a/Koha/Availability.pm b/Koha/Availability.pm >index a2e72a2..f9008ce 100644 >--- a/Koha/Availability.pm >+++ b/Koha/Availability.pm >@@ -213,4 +213,20 @@ sub unavailable { > } > } > >+ >+sub _swaggerize_exception { >+ my ($self, $exceptions) = @_; >+ >+ my $ret = {}; >+ foreach my $ex (keys %{$exceptions}) { >+ my $name = $ex; >+ $name =~ s/Koha::Exceptions:://; >+ $ret->{$name} = {}; >+ foreach my $field ($exceptions->{$ex}->Fields) { >+ $ret->{$name}->{$field} = $exceptions->{$ex}->$field; >+ } >+ } >+ return $ret; >+} >+ > 1; >diff --git a/Koha/Biblio/Availability.pm b/Koha/Biblio/Availability.pm >index 654457b..8cc875f 100644 >--- a/Koha/Biblio/Availability.pm >+++ b/Koha/Biblio/Availability.pm >@@ -19,6 +19,7 @@ package Koha::Biblio::Availability; > > use Modern::Perl; > use Scalar::Util qw(looks_like_number); >+use Mojo::JSON; > > use base qw(Koha::Availability); > >@@ -129,4 +130,49 @@ sub new { > return $self; > } > >+=head3 swaggerize >+ >+Returns a HASHref that contains biblio availability information as well as >+availability information for each item of this biblio. >+ >+Numifies numbers for Swagger to be numbers instead of strings. >+ >+=cut >+ >+sub swaggerize { >+ my ($self) = @_; >+ >+ my $item_availabilities = []; >+ foreach my $item_availability (@{$self->item_availabilities}) { >+ push $item_availabilities, $item_availability->swaggerize; >+ } >+ foreach my $item_availability (@{$self->item_unavailabilities}) { >+ push $item_availabilities, $item_availability->swaggerize; >+ } >+ my $confirmations = $self->SUPER::_swaggerize_exception($self->confirmations); >+ my $notes = $self->SUPER::_swaggerize_exception($self->notes); >+ my $unavailabilities = $self->SUPER::_swaggerize_exception($self->unavailabilities); >+ my $availability = { >+ available => $self->available >+ ? Mojo::JSON->true >+ : Mojo::JSON->false, >+ }; >+ if (keys %{$confirmations} > 0) { >+ $availability->{'confirmations'} = $confirmations; >+ } >+ if (keys %{$notes} > 0) { >+ $availability->{'notes'} = $notes; >+ } >+ if (keys %{$unavailabilities} > 0) { >+ $availability->{'unavailabilities'} = $unavailabilities; >+ } >+ >+ my $hash = { >+ biblionumber => 0+$self->biblio->biblionumber, >+ availability => $availability, >+ item_availabilities => $item_availabilities, >+ }; >+ return $hash; >+} >+ > 1; >diff --git a/Koha/Item/Availability.pm b/Koha/Item/Availability.pm >index c26d79b..7b4ef2d 100644 >--- a/Koha/Item/Availability.pm >+++ b/Koha/Item/Availability.pm >@@ -123,4 +123,49 @@ sub new { > return $self; > } > >+=head3 swaggerize >+ >+Returns a HASHref that contains item availability information. >+ >+Numifies numbers for Swagger to be numbers instead of strings. >+ >+=cut >+ >+sub swaggerize { >+ my ($self) = @_; >+ >+ my $confirmations = $self->SUPER::_swaggerize_exception($self->confirmations); >+ my $notes = $self->SUPER::_swaggerize_exception($self->notes); >+ my $unavailabilities = $self->SUPER::_swaggerize_exception($self->unavailabilities); >+ my $item = $self->item; >+ my $availability = { >+ available => $self->available >+ ? Mojo::JSON->true >+ : Mojo::JSON->false, >+ }; >+ if (keys %{$confirmations} > 0) { >+ $availability->{'confirmations'} = $confirmations; >+ } >+ if (keys %{$notes} > 0) { >+ $availability->{'notes'} = $notes; >+ } >+ if (keys %{$unavailabilities} > 0) { >+ $availability->{'unavailabilities'} = $unavailabilities; >+ } >+ >+ return { >+ itemnumber => 0+$item->itemnumber, >+ biblionumber => 0+$item->biblionumber, >+ biblioitemnumber => 0+$item->biblioitemnumber, >+ availability => $availability, >+ barcode => $item->barcode, >+ enumchron => $item->enumchron, >+ holdingbranch => $item->holdingbranch, >+ homebranch => $item->homebranch, >+ itemcallnumber => $item->itemcallnumber, >+ itemnotes => $item->itemnotes, >+ location => $item->location, >+ }; >+} >+ > 1; >diff --git a/api/v1/swagger/paths/availability.json b/api/v1/swagger/paths/availability.json >index d7ab4c6..2dbe03e 100644 >--- a/api/v1/swagger/paths/availability.json >+++ b/api/v1/swagger/paths/availability.json >@@ -6,7 +6,14 @@ > "parameters": [ > { "$ref": "../parameters.json#/biblionumbersQueryParam" }, > { "$ref": "../parameters.json#/borrowernumberQueryParam" }, >- { "$ref": "../parameters.json#/branchcodeQueryParam"} >+ { "$ref": "../parameters.json#/branchcodeQueryParam"}, >+ { >+ "name": "limit_items", >+ "in": "query", >+ "description": "Check only first n available items.", >+ "required": false, >+ "type": "integer" >+ } > ], > "consumes": ["application/json"], > "produces": ["application/json"], >-- >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 16826
:
53271
|
53276
|
53371
|
53672
|
53675
|
53813
|
53826
|
53827
|
53922
|
54053
|
56128
|
56129
|
56130
|
56295
|
57271
|
57321
|
57369
|
57370
|
57371
|
57373
|
57382
|
58456
|
58457
|
58458
|
60155
|
60156
|
60157
|
60218
|
60219
|
60267
|
60268
|
60269
|
62727