From f9568a01fccc46bd9bd61a3fc068bd3249510c57 Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Mon, 1 Apr 2019 12:08:53 +0000 Subject: [PATCH] Bug 22613: Add /patrons/{patron_id}/checkouts endpoint to REST API Test plan: 1) Apply the patch 2) Restart plack 3) Access GET to /patrons/{patron_id}/checkouts It should have the same abilities as /checkouts?patron_id={patron_id} 4) prove t/db_dependent/api/v1/checkouts.t Signed-off-by: Michal Denar Signed-off-by: Johanna Raisa Signed-off-by: Michal Denar Signed-off-by: Emmi Takkinen --- api/v1/swagger/paths.json | 4 +++ api/v1/swagger/paths/checkouts.json | 39 +++++++++++++++++++++++++++++ t/db_dependent/api/v1/checkouts.t | 12 ++++++++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/api/v1/swagger/paths.json b/api/v1/swagger/paths.json index d705760f63..20baf263ac 100644 --- a/api/v1/swagger/paths.json +++ b/api/v1/swagger/paths.json @@ -68,6 +68,10 @@ "/patrons/{patron_id}/account/credits": { "$ref": "paths/patrons_account.json#/~1patrons~1{patron_id}~1account~1credits" }, + "/patrons/{patron_id}/checkouts": { + "$ref": "paths/checkouts.json#/~1patrons~1{patron_id}~1checkouts" + }, + "/patrons/{patron_id}/password": { "$ref": "paths/patrons_password.json#/~1patrons~1{patron_id}~1password" }, diff --git a/api/v1/swagger/paths/checkouts.json b/api/v1/swagger/paths/checkouts.json index ca6d970dbb..1b42c7bf50 100644 --- a/api/v1/swagger/paths/checkouts.json +++ b/api/v1/swagger/paths/checkouts.json @@ -135,5 +135,44 @@ } } } + }, + "/patrons/{patron_id}/checkouts": { + "get": { + "x-mojo-to": "Checkouts#list", + "operationId": "listPatronsCheckouts", + "tags": ["patrons", "checkouts"], + "parameters": [{ + "$ref": "../parameters.json#/patron_id_pp" + },{ + "name": "checked_in", + "in": "query", + "description": "By default, only current checkout are returned, when this is true, all checkouts (current and checked in) are returned as result.", + "type": "boolean" + }], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "A list of checkouts", + "schema": { + "$ref": "../definitions.json#/checkouts" + } + }, + "403": { + "description": "Access forbidden", + "schema": { "$ref": "../definitions.json#/error" } + }, + "404": { + "description": "Patron not found", + "schema": { "$ref": "../definitions.json#/error" } + } + }, + "x-koha-authorization": { + "permissions": { + "circulate": "circulate_remaining_permissions" + } + } + } } } diff --git a/t/db_dependent/api/v1/checkouts.t b/t/db_dependent/api/v1/checkouts.t index 5a3447412e..5aaf7e4c75 100644 --- a/t/db_dependent/api/v1/checkouts.t +++ b/t/db_dependent/api/v1/checkouts.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 93; +use Test::More tests => 102; use Test::MockModule; use Test::Mojo; use t::lib::Mocks; @@ -152,6 +152,16 @@ $t->get_ok( "//$userid:$password@/api/v1/checkouts?patron_id=$patron_id&_per_pag ->json_is('/0/due_date' => output_pref({ dateformat => "rfc3339", dt => $date_due2 }) ) ->json_hasnt('/1'); +$t->get_ok( "//$userid:$password@/api/v1/patrons/$patron_id/checkouts") + ->status_is(200) + ->json_is('/0/patron_id' => $patron_id) + ->json_is('/0/item_id' => $item1->itemnumber) + ->json_is('/0/due_date' => output_pref({ dateformat => "rfc3339", dt => $date_due1 }) ) + ->json_is('/1/patron_id' => $patron_id) + ->json_is('/1/item_id' => $item2->itemnumber) + ->json_is('/1/due_date' => output_pref({ dateformat => "rfc3339", dt => $date_due2 }) ) + ->json_hasnt('/2'); + $t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue1->issue_id) ->status_is(200) ->json_is('/patron_id' => $patron_id) -- 2.17.1