Bugzilla – Attachment 53823 Details for
Bug 17007
REST API: add route to get biblio
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17007: REST API: add route to get biblio
Bug-17007-REST-API-add-route-to-get-biblio.patch (text/plain), 17.10 KB, created by
Jiri Kozlovsky
on 2016-08-01 03:04:58 UTC
(
hide
)
Description:
Bug 17007: REST API: add route to get biblio
Filename:
MIME Type:
Creator:
Jiri Kozlovsky
Created:
2016-08-01 03:04:58 UTC
Size:
17.10 KB
patch
obsolete
>From d6188c39851d52d2f609652a3dc5d7d6ab336b49 Mon Sep 17 00:00:00 2001 >From: Jiri Kozlovsky <mail@jkozlovsky.cz> >Date: Mon, 1 Aug 2016 04:44:04 +0200 >Subject: [PATCH] Bug 17007: REST API: add route to get biblio > >--- > Koha/REST/V1/Biblio.pm | 46 ++++++++++ > api/v1/definitions/biblio.json | 59 ++++++++++++ > api/v1/definitions/biblioitems.json | 56 ++++++++++++ > api/v1/definitions/index.json | 2 + > api/v1/definitions/item.json | 177 ++++++++++++++++++++++++++++++++++++ > api/v1/swagger.json | 32 +++++++ > t/db_dependent/api/v1/biblios.t | 116 +++++++++++++++++++++++ > 7 files changed, 488 insertions(+) > create mode 100644 Koha/REST/V1/Biblio.pm > create mode 100644 api/v1/definitions/biblio.json > create mode 100644 api/v1/definitions/biblioitems.json > create mode 100644 api/v1/definitions/item.json > create mode 100644 t/db_dependent/api/v1/biblios.t > >diff --git a/Koha/REST/V1/Biblio.pm b/Koha/REST/V1/Biblio.pm >new file mode 100644 >index 0000000..d7206d7 >--- /dev/null >+++ b/Koha/REST/V1/Biblio.pm >@@ -0,0 +1,46 @@ >+package Koha::REST::V1::Biblio; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Mojo::Base 'Mojolicious::Controller'; >+use Mojo::JSON; >+ >+use C4::Auth qw( haspermission ); >+ >+use Koha::Biblios; >+use Koha::Items; >+ >+sub get { >+ my ($c, $args, $cb) = @_; >+ >+ my $biblionumber = $c->param('biblionumber'); >+ my $biblio = Koha::Biblios->find($biblionumber); >+ >+ unless ($biblio) { >+ return $c->$cb({error => "Biblio not found"}, 404); >+ } >+ >+ my $items = $biblio->items(); >+ >+ $biblio = $biblio->unblessed; >+ $biblio->{items} = $items->unblessed; >+ >+ return $c->$cb($biblio, 200); >+} >+ >+1; >diff --git a/api/v1/definitions/biblio.json b/api/v1/definitions/biblio.json >new file mode 100644 >index 0000000..3403e1b >--- /dev/null >+++ b/api/v1/definitions/biblio.json >@@ -0,0 +1,59 @@ >+{ >+ "type": "object", >+ "properties": { >+ "biblionumber": { >+ "type": "string", >+ "description": "unique identifier assigned to each bibliographic record" >+ }, >+ "frameworkcode": { >+ "type": "string", >+ "description": "foreign key from the biblio_framework table to identify which framework was used in cataloging this record" >+ }, >+ "author": { >+ "type": ["string", "null"], >+ "description": "statement of responsibility from MARC record (100$a in MARC21)" >+ }, >+ "title": { >+ "type": ["string", "null"], >+ "description": "title (without the subtitle) from the MARC record (245$a in MARC21)" >+ }, >+ "untitle": { >+ "type": ["string", "null"], >+ "description": "uniform title (without the subtitle) from the MARC record (240$a in MARC21)" >+ }, >+ "notes": { >+ "type": ["string", "null"], >+ "description": "values from the general notes field in the MARC record (500$a in MARC21) split by bar (|)" >+ }, >+ "serial": { >+ "type": ["string", "null"], >+ "description": "Boolean indicating whether biblio is for a serial" >+ }, >+ "seriestitle": { >+ "type": ["string", "null"], >+ "description": "Title for describing the series" >+ }, >+ "copyrightdate": { >+ "type": ["string", "null"], >+ "description": "publication or copyright date from the MARC record" >+ }, >+ "timestamp": { >+ "type": "string", >+ "description": "date and time this record was last touched" >+ }, >+ "datecreated": { >+ "type": "string", >+ "description": "the date this record was added to Koha" >+ }, >+ "abstract": { >+ "type": ["string", "null"], >+ "description": "summary from the MARC record (520$a in MARC21)" >+ }, >+ "items": { >+ "type": "array", >+ "items": { >+ "$ref": "item.json" >+ } >+ } >+ } >+} >diff --git a/api/v1/definitions/biblioitems.json b/api/v1/definitions/biblioitems.json >new file mode 100644 >index 0000000..f6b3f64 >--- /dev/null >+++ b/api/v1/definitions/biblioitems.json >@@ -0,0 +1,56 @@ >+{ >+ "type": "object", >+ "properties": { >+ "biblionumber": { >+ "type": "string", >+ "description": "unique identifier assigned to each bibliographic record" >+ }, >+ "frameworkcode": { >+ "type": "string", >+ "description": "foreign key from the biblio_framework table to identify which framework was used in cataloging this record" >+ }, >+ "author": { >+ "type": ["string", "null"], >+ "description": "statement of responsibility from MARC record (100$a in MARC21)" >+ }, >+ "title": { >+ "type": ["string", "null"], >+ "description": "title (without the subtitle) from the MARC record (245$a in MARC21)" >+ }, >+ "untitle": { >+ "type": ["string", "null"], >+ "description": "uniform title (without the subtitle) from the MARC record (240$a in MARC21)" >+ }, >+ "notes": { >+ "type": ["string", "null"], >+ "description": "values from the general notes field in the MARC record (500$a in MARC21) split by bar (|)" >+ }, >+ "serial": { >+ "type": ["boolean", "null"], >+ "description": "Boolean indicating whether biblio is for a serial" >+ }, >+ "seriestitle": { >+ "type": ["string", "null"], >+ "description": "Title for describing the series" >+ }, >+ "copyrightdate": { >+ "type": ["string", "null"], >+ "description": "publication or copyright date from the MARC record" >+ }, >+ "timestamp": { >+ "type": "string", >+ "description": "date and time this record was last touched" >+ }, >+ "datecreated": { >+ "type": "string", >+ "description": "the date this record was added to Koha" >+ }, >+ "abstract": { >+ "type": ["string", "null"], >+ "description": "summary from the MARC record (520$a in MARC21)" >+ }, >+ "items": { >+ "$ref": "biblioitems.json" >+ } >+ } >+} >diff --git a/api/v1/definitions/index.json b/api/v1/definitions/index.json >index 3f69544..3d1a43f 100644 >--- a/api/v1/definitions/index.json >+++ b/api/v1/definitions/index.json >@@ -2,5 +2,7 @@ > "patron": { "$ref": "patron.json" }, > "holds": { "$ref": "holds.json" }, > "hold": { "$ref": "hold.json" }, >+ "item": { "$ref": "item.json" }, >+ "biblio": { "$ref": "biblio.json" }, > "error": { "$ref": "error.json" } > } >diff --git a/api/v1/definitions/item.json b/api/v1/definitions/item.json >new file mode 100644 >index 0000000..9c43f85 >--- /dev/null >+++ b/api/v1/definitions/item.json >@@ -0,0 +1,177 @@ >+{ >+ "type": "object", >+ "properties": { >+ "itemnumber": { >+ "type": "string", >+ "description": "internally assigned item identifier" >+ }, >+ "biblionumber": { >+ "type": "string", >+ "description": "internally assigned biblio identifier" >+ }, >+ "biblioitemnumber": { >+ "type": "string", >+ "description": "internally assigned biblio item identifier" >+ }, >+ "barcode": { >+ "type": ["string", "null"], >+ "description": "item barcode" >+ }, >+ "dateaccessioned": { >+ "type": ["string", "null"], >+ "description": "date the item was acquired or added to Koha" >+ }, >+ "booksellerid": { >+ "type": ["string", "null"], >+ "description": "where the item was purchased" >+ }, >+ "homebranch": { >+ "type": ["string", "null"], >+ "description": "library that owns this item" >+ }, >+ "price": { >+ "type": ["string", "null"], >+ "description": "purchase price" >+ }, >+ "replacementprice": { >+ "type": ["string", "null"], >+ "description": "cost the library charges to replace the item if it has been marked lost" >+ }, >+ "replacementpricedate": { >+ "type": ["string", "null"], >+ "description": "the date the price is effective from" >+ }, >+ "datelastborrowed": { >+ "type": ["string", "null"], >+ "description": "the date the item was last checked out/issued" >+ }, >+ "datelastseen": { >+ "type": ["string", "null"], >+ "description": "the date the item was last see (usually the last time the barcode was scanned or inventory was done)" >+ }, >+ "stack": { >+ "type": ["string", "null"], >+ "description": "?" >+ }, >+ "notforloan": { >+ "type": "string", >+ "description": "authorized value defining why this item is not for loan" >+ }, >+ "damaged": { >+ "type": "string", >+ "description": "authorized value defining this item as damaged" >+ }, >+ "itemlost": { >+ "type": "string", >+ "description": "authorized value defining this item as lost" >+ }, >+ "itemlost_on": { >+ "type": ["string", "null"], >+ "description": "the date and time an item was last marked as lost, NULL if not lost" >+ }, >+ "withdrawn": { >+ "type": "string", >+ "description": "authorized value defining this item as withdrawn" >+ }, >+ "withdrawn_on": { >+ "type": ["string", "null"], >+ "description": "the date and time an item was last marked as withdrawn, NULL if not withdrawn" >+ }, >+ "itemcallnumber": { >+ "type": ["string", "null"], >+ "description": "call number for this item" >+ }, >+ "coded_location_qualifier": { >+ "type": ["string", "null"], >+ "description": "coded location qualifier" >+ }, >+ "issues": { >+ "type": ["string", "null"], >+ "description": "number of times this item has been checked out/issued" >+ }, >+ "renewals": { >+ "type": ["string", "null"], >+ "description": "number of times this item has been renewed" >+ }, >+ "reserves": { >+ "type": ["string", "null"], >+ "description": "number of times this item has been placed on hold/reserved" >+ }, >+ "restricted": { >+ "type": ["string", "null"], >+ "description": "authorized value defining use restrictions for this item" >+ }, >+ "itemnotes": { >+ "type": ["string", "null"], >+ "description": "public notes on this item" >+ }, >+ "itemnotes_nonpublic": { >+ "type": ["string", "null"], >+ "description": "non-public notes on this item" >+ }, >+ "holdingbranch": { >+ "type": ["string", "null"], >+ "description": "library that is currently in possession item" >+ }, >+ "paidfor": { >+ "type": ["string", "null"], >+ "description": "?" >+ }, >+ "timestamp": { >+ "type": "string", >+ "description": "date and time this item was last altered" >+ }, >+ "location": { >+ "type": ["string", "null"], >+ "description": "authorized value for the shelving location for this item" >+ }, >+ "permanent_location": { >+ "type": ["string", "null"], >+ "description": "linked to the CART and PROC temporary locations feature, stores the permanent shelving location" >+ }, >+ "onloan": { >+ "type": ["string", "null"], >+ "description": "defines if item is checked out (NULL for not checked out, and checkout date for checked out)" >+ }, >+ "cn_source": { >+ "type": ["string", "null"], >+ "description": "classification source used on this item" >+ }, >+ "cn_sort": { >+ "type": ["string", "null"], >+ "description": "?" >+ }, >+ "ccode": { >+ "type": ["string", "null"], >+ "description": "authorized value for the collection code associated with this item" >+ }, >+ "materials": { >+ "type": ["string", "null"], >+ "description": "materials specified" >+ }, >+ "uri": { >+ "type": ["string", "null"], >+ "description": "URL for the item" >+ }, >+ "itype": { >+ "type": ["string", "null"], >+ "description": "itemtype defining the type for this item" >+ }, >+ "more_subfields_xml": { >+ "type": ["string", "null"], >+ "description": "additional 952 subfields in XML format" >+ }, >+ "enumchron": { >+ "type": ["string", "null"], >+ "description": "serial enumeration/chronology for the item" >+ }, >+ "copynumber": { >+ "type": ["string", "null"], >+ "description": "copy number" >+ }, >+ "stocknumber": { >+ "type": ["string", "null"], >+ "description": "inventory number" >+ } >+ } >+} >diff --git a/api/v1/swagger.json b/api/v1/swagger.json >index b3f30f8..2bc6aa7 100644 >--- a/api/v1/swagger.json >+++ b/api/v1/swagger.json >@@ -332,6 +332,31 @@ > } > } > } >+ }, >+ "/biblios/{biblionumber}": { >+ "get": { >+ "operationId": "getBiblio", >+ "tags": ["biblios"], >+ "parameters": [ >+ { "$ref": "#/parameters/biblionumberPathParam" } >+ ], >+ "consumes": ["application/json"], >+ "produces": ["application/json"], >+ "responses": { >+ "200": { >+ "description": "An biblio", >+ "schema": { "$ref": "#/definitions/biblio" } >+ }, >+ "400": { >+ "description": "Missing or wrong parameters", >+ "schema": { "$ref": "#/definitions/error" } >+ }, >+ "404": { >+ "description": "Biblio not found", >+ "schema": { "$ref": "#/definitions/error" } >+ } >+ } >+ } > } > }, > "definitions": { >@@ -351,6 +376,13 @@ > "description": "Internal hold identifier", > "required": true, > "type": "integer" >+ }, >+ "biblionumberPathParam": { >+ "name": "biblionumber", >+ "in": "path", >+ "description": "Internal biblio identifier", >+ "required": true, >+ "type": "integer" > } > } > } >diff --git a/t/db_dependent/api/v1/biblios.t b/t/db_dependent/api/v1/biblios.t >new file mode 100644 >index 0000000..848fb7a >--- /dev/null >+++ b/t/db_dependent/api/v1/biblios.t >@@ -0,0 +1,116 @@ >+#!/usr/bin/env perl >+ >+# Copyright 2016 Koha-Suomi >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Test::More tests => 7; >+use Test::Mojo; >+use t::lib::TestBuilder; >+ >+use C4::Auth; >+use C4::Biblio; >+use C4::Context; >+use C4::Items; >+ >+use Koha::Database; >+use Koha::Patron; >+use Koha::Items; >+ >+my $builder = t::lib::TestBuilder->new(); >+ >+my $dbh = C4::Context->dbh; >+$dbh->{AutoCommit} = 0; >+$dbh->{RaiseError} = 1; >+ >+$ENV{REMOTE_ADDR} = '127.0.0.1'; >+my $t = Test::Mojo->new('Koha::REST::V1'); >+ >+my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; >+my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; >+my $borrower = $builder->build({ >+ source => 'Borrower', >+ value => { >+ branchcode => $branchcode, >+ categorycode => $categorycode, >+ flags => 16, >+ } >+}); >+ >+my $librarian = $builder->build({ >+ source => "Borrower", >+ value => { >+ categorycode => $categorycode, >+ branchcode => $branchcode, >+ flags => 4, >+ }, >+}); >+ >+my ($session) = create_session($borrower); >+ >+my $biblio = $builder->build({ >+ source => 'Biblio' >+}); >+my $biblionumber = $biblio->{biblionumber}; >+my $item1 = $builder->build({ >+ source => 'Item', >+ value => { >+ biblionumber => $biblionumber, >+ } >+}); >+my $item2 = $builder->build({ >+ source => 'Item', >+ value => { >+ biblionumber => $biblionumber, >+ } >+}); >+my $item1number = $item1->{itemnumber}; >+my $item2number = $item2->{itemnumber}; >+ >+my $nonExistentBiblionumber = -14362719; >+my $tx = $t->ua->build_tx(GET => "/api/v1/biblios/$nonExistentBiblionumber"); >+$tx->req->cookies({name => 'CGISESSID', value => $session->id}); >+$t->request_ok($tx) >+ ->status_is(404); >+ >+$tx = $t->ua->build_tx(GET => "/api/v1/biblios/$biblionumber"); >+$tx->req->cookies({name => 'CGISESSID', value => $session->id}); >+$t->request_ok($tx) >+ ->status_is(200) >+ ->json_is('/items/0/itemnumber' => $item1number) >+ ->json_is('/items/1/itemnumber' => $item2number) >+ ->json_is('/biblionumber' => $biblionumber); >+ >+$dbh->rollback; >+ >+sub create_session { >+ my (@borrowers) = @_; >+ >+ my @sessions; >+ foreach $borrower (@borrowers) { >+ my $session = C4::Auth::get_session(''); >+ $session->param('number', $borrower->{borrowernumber}); >+ $session->param('id', $borrower->{userid}); >+ $session->param('ip', '127.0.0.1'); >+ $session->param('lasttime', time()); >+ $session->flush; >+ push @sessions, $session; >+ } >+ >+ return @sessions; >+} >-- >2.1.4
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 17007
:
53823
|
53824
|
53825
|
53834
|
53836
|
54187
|
54193