Bugzilla – Attachment 53843 Details for
Bug 17005
Extend /checkouts route to list circulation history
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17005: REST API: add routes to list checkouts history
Bug-17005-REST-API-add-routes-to-list-checkouts-hi.patch (text/plain), 5.38 KB, created by
Jiri Kozlovsky
on 2016-08-01 15:24:10 UTC
(
hide
)
Description:
Bug 17005: REST API: add routes to list checkouts history
Filename:
MIME Type:
Creator:
Jiri Kozlovsky
Created:
2016-08-01 15:24:10 UTC
Size:
5.38 KB
patch
obsolete
>From c6031560e5c6d36235707b1255c2ae50726a5238 Mon Sep 17 00:00:00 2001 >From: Jiri Kozlovsky <mail@jkozlovsky.cz> >Date: Mon, 1 Aug 2016 17:17:17 +0200 >Subject: [PATCH] Bug 17005: REST API: add routes to list checkouts history > >GET /checkouts/history (get all old_issues' issue_id) >GET /checkouts/history?borrowernumber={borrowernumber} (get all borrower's old_issues) >GET /checkouts/history/{checkout_id} (get old_issue) > >+ unit tests in t/db_dependent/api/v1/checkoutshistory.t > >Test plan: >1. Open a browser tab on Koha staff and log in (to create CGISESSID > cookie). You should have permission circulate_remaining_permissions. >2. Go to http://yourlibrary/api/v1/checkouts/history?borrowernumber=XXX (replace > XXX with a borrowernumber that has some checkouts history) and check you receive > correct data >3. Go to http://yourlibrary/api/v1/checkouts/history/YYY (replace YYY with an > existing checkout id) and check you receive correct data >4. Run unit tests in t/db_dependent/api/v1/checkoutshistory.t > >Depends on bug 13895 >--- > Koha/REST/V1/Checkout.pm | 54 +++++++++++++++++++++++++++++++++++++++ > api/v1/swagger.json | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 120 insertions(+) > >diff --git a/Koha/REST/V1/Checkout.pm b/Koha/REST/V1/Checkout.pm >index 68046a6..e044fab 100644 >--- a/Koha/REST/V1/Checkout.pm >+++ b/Koha/REST/V1/Checkout.pm >@@ -15,6 +15,9 @@ package Koha::REST::V1::Checkout; > # with Koha; if not, write to the Free Software Foundation, Inc., > # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. > >+use strict; >+use warnings; >+ > use Modern::Perl; > > use Mojo::Base 'Mojolicious::Controller'; >@@ -22,6 +25,7 @@ use Mojo::Base 'Mojolicious::Controller'; > use C4::Auth qw( haspermission ); > use C4::Circulation; > use Koha::Issues; >+use Koha::OldIssues; > > sub list { > my ($c, $args, $cb) = @_; >@@ -94,4 +98,54 @@ sub renew { > return $c->$cb($checkout->unblessed, 200); > } > >+sub listhistory { >+ my ($c, $args, $cb) = @_; >+ >+ my $user = $c->stash('koha.user'); >+ unless ($user && haspermission($user->userid, { circulate => "circulate_remaining_permissions" })) { >+ return $c->$cb({error => "You don't have the required permission"}, 403); >+ } >+ >+ my $borrowernumber = $c->param('borrowernumber'); >+ >+ my $checkouts; >+ >+ if ($borrowernumber) { >+ >+ $checkouts = Koha::OldIssues->search({ >+ borrowernumber => $borrowernumber >+ })->unblessed; >+ >+ } else { >+ >+ # Retrieve all the issues in the history, but only the issue_id due to possible perfomance issues >+ $checkouts = Koha::OldIssues->search({}, { >+ columns => [qw/issue_id/], >+ })->unblessed; >+ >+ } >+ >+ $c->$cb($checkouts, 200); >+} >+ >+sub gethistory { >+ my ($c, $args, $cb) = @_; >+ >+ my $user = $c->stash('koha.user'); >+ unless ($user && haspermission($user->userid, { circulate => "circulate_remaining_permissions" })) { >+ return $c->$cb({error => "You don't have the required permission"}, 403); >+ } >+ >+ my $checkout_id = $args->{checkout_id}; >+ my $checkout = Koha::OldIssues->find($checkout_id); >+ >+ if (!$checkout) { >+ return $c->$cb({ >+ error => "Checkout doesn't exist" >+ }, 404); >+ } >+ >+ return $c->$cb($checkout->unblessed, 200); >+} >+ > 1; >diff --git a/api/v1/swagger.json b/api/v1/swagger.json >index 68eeea6..c590613 100644 >--- a/api/v1/swagger.json >+++ b/api/v1/swagger.json >@@ -426,6 +426,72 @@ > } > } > } >+ }, >+ "/checkouts/history": { >+ "get": { >+ "operationId": "listhistoryCheckouts", >+ "tags": ["borrowers", "checkouts"], >+ "parameters": [ >+ { >+ "name": "borrowernumber", >+ "in": "query", >+ "description": "Internal patron identifier", >+ "required": false, >+ "type": "integer" >+ } >+ ], >+ "produces": [ >+ "application/json" >+ ], >+ "responses": { >+ "200": { >+ "description": "A list of checkouts history", >+ "schema": { >+ "$ref": "#/definitions/checkouts" >+ } >+ }, >+ "403": { >+ "description": "Access forbidden", >+ "schema": { "$ref": "#/definitions/error" } >+ }, >+ "404": { >+ "description": "Borrower not found", >+ "schema": { >+ "$ref": "#/definitions/error" >+ } >+ } >+ } >+ } >+ }, >+ "/checkouts/history/{checkout_id}": { >+ "get": { >+ "operationId": "gethistoryCheckout", >+ "tags": ["borrowers", "checkouts"], >+ "parameters": [ >+ { >+ "name": "checkout_id", >+ "in": "path", >+ "description": "Internal checkout identifier", >+ "required": true, >+ "type": "integer" >+ } >+ ], >+ "produces": ["application/json"], >+ "responses": { >+ "200": { >+ "description": "Got borrower's checkout", >+ "schema": { "$ref": "#/definitions/checkout" } >+ }, >+ "403": { >+ "description": "Access forbidden", >+ "schema": { "$ref": "#/definitions/error" } >+ }, >+ "404": { >+ "description": "Checkout not found", >+ "schema": { "$ref": "#/definitions/error" } >+ } >+ } >+ } > } > }, > "definitions": { >-- >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 17005
:
53843
|
53851
|
53852
|
53858
|
54198
|
56698
|
56699
|
61197
|
87254
|
87255
|
87383
|
87384
|
87385
|
87405
|
87406
|
87407
|
87442
|
87443
|
87444
|
87447
|
87448
|
87449
|
88263
|
88264
|
88265
|
88329
|
88330
|
88331
|
91166
|
91167
|
91168
|
91235
|
91236
|
91237
|
91238
|
93757
|
93758
|
93759
|
93760