Bugzilla – Attachment 53819 Details for
Bug 16497
Add routes for library retrieval, update and deletion
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16497 - REST API: add routes to list libraries
Bug-16497---REST-API-add-routes-to-list-libraries.patch (text/plain), 10.04 KB, created by
Jiri Kozlovsky
on 2016-07-31 09:49:26 UTC
(
hide
)
Description:
Bug 16497 - REST API: add routes to list libraries
Filename:
MIME Type:
Creator:
Jiri Kozlovsky
Created:
2016-07-31 09:49:26 UTC
Size:
10.04 KB
patch
obsolete
>From 169baa51ad2e73700322b88d18cb664cec55cd66 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Ji=C5=99=C3=AD=20Kozlovsk=C3=BD?= <mail@jkozlovsky.cz> >Date: Sun, 31 Jul 2016 11:46:57 +0200 >Subject: [PATCH] Bug 16497 - REST API: add routes to list libraries >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Simple routes to list all or get one Library >GET /api/v1/libraries - List all libraries >GET /api/v1/libraries/{branchcode} - Get one Library > >Test plan: > - apply patch > - run tests: t/db_dependent/api/v1/libraries.t > - test API with some API tool or simple curl > >e.g.: >curl http://host:port/api/v1/libraries >curl http://host:port/api/v1/libraries/cpl > >Signed-off-by: Lari Taskula <larit@student.uef.fi> >Signed-off-by: JiÅà Kozlovský <mail@jkozlovsky.cz> >--- > Koha/REST/V1/Library.pm | 42 +++++++++++++++++++++ > api/v1/definitions/index.json | 2 + > api/v1/definitions/libraries.json | 4 ++ > api/v1/definitions/library.json | 77 +++++++++++++++++++++++++++++++++++++++ > api/v1/swagger.json | 50 +++++++++++++++++++++++++ > t/db_dependent/api/v1/libraries.t | 63 ++++++++++++++++++++++++++++++++ > 6 files changed, 238 insertions(+) > create mode 100644 Koha/REST/V1/Library.pm > create mode 100644 api/v1/definitions/libraries.json > create mode 100644 api/v1/definitions/library.json > create mode 100644 t/db_dependent/api/v1/libraries.t > >diff --git a/Koha/REST/V1/Library.pm b/Koha/REST/V1/Library.pm >new file mode 100644 >index 0000000..30a8982 >--- /dev/null >+++ b/Koha/REST/V1/Library.pm >@@ -0,0 +1,42 @@ >+package Koha::REST::V1::Library; >+ >+# 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 Koha::Libraries; >+ >+sub list { >+ my ($c, $args, $cb) = @_; >+ >+ my $libraries = Koha::Libraries->search; >+ return $c->$cb($libraries->unblessed, 200); >+} >+ >+sub get { >+ my ($c, $args, $cb) = @_; >+ >+ my $brancocode = $c->param('branchcode'); >+ my $library = Koha::Libraries->find({branchcode => $brancocode}); >+ unless ($library) { >+ return $c->$cb({error => "Library with branchcode \"$brancocode\" not found"}, 404); >+ } >+ >+ return $c->$cb($library->unblessed, 200); >+} >+ >+1; >diff --git a/api/v1/definitions/index.json b/api/v1/definitions/index.json >index 3f69544..cedcc3c 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" }, >+ "libraries": { "$ref": "libraries.json" }, >+ "library": { "$ref": "library.json" }, > "error": { "$ref": "error.json" } > } >diff --git a/api/v1/definitions/libraries.json b/api/v1/definitions/libraries.json >new file mode 100644 >index 0000000..a79fd34 >--- /dev/null >+++ b/api/v1/definitions/libraries.json >@@ -0,0 +1,4 @@ >+{ >+ "type": "array", >+ "items": { "$ref": "library.json" } >+} >diff --git a/api/v1/definitions/library.json b/api/v1/definitions/library.json >new file mode 100644 >index 0000000..f841899 >--- /dev/null >+++ b/api/v1/definitions/library.json >@@ -0,0 +1,77 @@ >+{ >+ "type": "object", >+ "properties": { >+ "branchcode": { >+ "type": "string", >+ "description": "Internal library identifier" >+ }, >+ "branchname": { >+ "type": "string", >+ "description": "Printable name of library" >+ }, >+ "branchaddress1": { >+ "type": ["string", "null"], >+ "description": "the first address line of the library" >+ }, >+ "branchaddress2": { >+ "type": ["string", "null"], >+ "description": "the second address line of the library" >+ }, >+ "branchaddress3": { >+ "type": ["string", "null"], >+ "description": "the third address line of the library" >+ }, >+ "branchzip": { >+ "type": ["string", "null"], >+ "description": "the zip or postal code of the library" >+ }, >+ "branchcity": { >+ "type": ["string", "null"], >+ "description": "the city or province of the library" >+ }, >+ "branchstate": { >+ "type": ["string", "null"], >+ "description": "the reqional state of the library" >+ }, >+ "branchcountry": { >+ "type": ["string", "null"], >+ "description": "the county of the library" >+ }, >+ "branchphone": { >+ "type": ["string", "null"], >+ "description": "the primary phone of the library" >+ }, >+ "branchfax": { >+ "type": ["string", "null"], >+ "description": "the fax number of the library" >+ }, >+ "branchemail": { >+ "type": ["string", "null"], >+ "description": "the primary email address of the library" >+ }, >+ "branchreplyto": { >+ "type": ["string", "null"], >+ "description": "the email to be used as a Reply-To" >+ }, >+ "branchreturnpath": { >+ "type": ["string", "null"], >+ "description": "the email to be used as Return-Path" >+ }, >+ "branchurl": { >+ "type": ["string", "null"], >+ "description": "the URL for your library or branch's website" >+ }, >+ "branchip": { >+ "type": ["string", "null"], >+ "description": "the IP address for your library or branch" >+ }, >+ "branchnotes": { >+ "type": ["string", "null"], >+ "description": "notes related to your library or branch" >+ }, >+ "opac_info": { >+ "type": ["string", "null"], >+ "description": "HTML that displays in OPAC" >+ } >+ } >+} >diff --git a/api/v1/swagger.json b/api/v1/swagger.json >index b3f30f8..89ffcac 100644 >--- a/api/v1/swagger.json >+++ b/api/v1/swagger.json >@@ -332,6 +332,49 @@ > } > } > } >+ }, >+ "/libraries": { >+ "get": { >+ "operationId": "listLibrary", >+ "tags": ["libraries"], >+ "produces": [ >+ "application/json" >+ ], >+ "responses": { >+ "200": { >+ "description": "A list of libraries", >+ "schema": { >+ "$ref": "#/definitions/libraries" >+ } >+ } >+ } >+ } >+ }, >+ "/libraries/{branchcode}": { >+ "get": { >+ "operationId": "getLibrary", >+ "tags": ["libraries"], >+ "parameters": [ >+ { "$ref": "#/parameters/branchcodePathParam" } >+ ], >+ "produces": [ >+ "application/json" >+ ], >+ "responses": { >+ "200": { >+ "description": "A library", >+ "schema": { >+ "$ref": "#/definitions/library" >+ } >+ }, >+ "404": { >+ "description": "Library not found", >+ "schema": { >+ "$ref": "#/definitions/error" >+ } >+ } >+ } >+ } > } > }, > "definitions": { >@@ -351,6 +394,13 @@ > "description": "Internal hold identifier", > "required": true, > "type": "integer" >+ }, >+ "branchcodePathParam": { >+ "name": "branchcode", >+ "in": "path", >+ "description": "Internal library identifier", >+ "required": true, >+ "type": "string" > } > } > } >diff --git a/t/db_dependent/api/v1/libraries.t b/t/db_dependent/api/v1/libraries.t >new file mode 100644 >index 0000000..1f8a936 >--- /dev/null >+++ b/t/db_dependent/api/v1/libraries.t >@@ -0,0 +1,63 @@ >+#!/usr/bin/env perl >+ >+# 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 t::lib::TestBuilder; >+ >+use Test::More tests => 11; >+use Test::Mojo; >+ >+use C4::Auth; >+use C4::Context; >+use Koha::Database; >+ >+BEGIN { >+ use_ok('Koha::Object'); >+ use_ok('Koha::Libraries'); >+} >+ >+my $schema = Koha::Database->schema; >+my $dbh = C4::Context->dbh; >+my $builder = t::lib::TestBuilder->new; >+ >+$ENV{REMOTE_ADDR} = '127.0.0.1'; >+my $t = Test::Mojo->new('Koha::REST::V1'); >+ >+$schema->storage->txn_begin; >+ >+my $branch = $builder->build({ source => 'Branch' }); >+ >+my $tx = $t->ua->build_tx(GET => '/api/v1/libraries'); >+#$tx->req->cookies({name => 'CGISESSID', value => $session->id}); >+$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); >+$t->request_ok($tx) >+ ->status_is(200); >+ >+$tx = $t->ua->build_tx(GET => "/api/v1/libraries/" . $branch->{ branchcode }); >+#$tx->req->cookies({name => 'CGISESSID', value => $session->id}); >+$t->request_ok($tx) >+ ->status_is(200) >+ ->json_is('/branchcode' => $branch->{ branchcode }) >+ ->json_is('/branchname' => $branch->{ branchname }); >+ >+$tx = $t->ua->build_tx(GET => "/api/v1/libraries/" . "nonexistent"); >+$t->request_ok($tx) >+ ->status_is(404) >+ ->json_is('/error' => "Library with branchcode \"nonexistent\" not found"); >+ >+$schema->storage->txn_rollback; >-- >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 16497
:
51454
|
52905
|
53818
|
53819
|
54943
|
60801
|
60802
|
61164
|
61165
|
63160
|
63161
|
66837
|
66838
|
68746
|
68747
|
68748
|
68838
|
68839
|
68840
|
68841
|
69508
|
83913
|
83914
|
83915
|
83916
|
83917
|
83943
|
83945
|
83946
|
83947
|
83948
|
83949
|
84198
|
84588
|
84589
|
84590
|
84591
|
84592
|
84593
|
84734
|
84769