Bugzilla – Attachment 159067 Details for
Bug 35353
Add API endpoint to fetch patron's previous holds
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35353: Add api endpoint to fetch patron's previous holds
Bug-35353-Add-api-endpoint-to-fetch-patrons-previo.patch (text/plain), 7.12 KB, created by
ByWater Sandboxes
on 2023-11-16 21:52:12 UTC
(
hide
)
Description:
Bug 35353: Add api endpoint to fetch patron's previous holds
Filename:
MIME Type:
Creator:
ByWater Sandboxes
Created:
2023-11-16 21:52:12 UTC
Size:
7.12 KB
patch
obsolete
>From a0498a2331dcee993853622bd616674aa28421e8 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Thu, 16 Nov 2023 10:15:06 -0500 >Subject: [PATCH] Bug 35353: Add api endpoint to fetch patron's previous holds > >We have an endpoint to fetch a patron's current holds ( /api/va/patrons/$id/holds ) but some external services need to get previous holds to see if they were completed/canceled/etc. > >Test Plan: >1) Create some holds for a patron >2) Complete or cancel those holds >3) Browse to /api/va/patrons/$id/holds/previous where $id is the > borrowernumber >4) You should get a list of previous holds! > >Signed-off-by: Andrew Fuerste-Henry <andrewfh@dubcolib.org> >--- > Koha/REST/V1/Patrons/Holds.pm | 34 ++++++++++++++ > api/v1/swagger/paths/patrons_holds.yaml | 61 +++++++++++++++++++++++++ > api/v1/swagger/swagger.yaml | 2 + > t/db_dependent/api/v1/patrons_holds.t | 47 ++++++++++++++++++- > 4 files changed, 143 insertions(+), 1 deletion(-) > >diff --git a/Koha/REST/V1/Patrons/Holds.pm b/Koha/REST/V1/Patrons/Holds.pm >index 88eea15b53..1f62db4fc9 100644 >--- a/Koha/REST/V1/Patrons/Holds.pm >+++ b/Koha/REST/V1/Patrons/Holds.pm >@@ -63,6 +63,40 @@ sub list { > }; > } > >+=head3 list_old >+ >+Controller function that handles listing Koha::Old::Hold objects for the requested patron >+ >+=cut >+ >+sub list_old { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $patron = Koha::Patrons->find( $c->param('patron_id') ); >+ >+ unless ( $patron ) { >+ return $c->render( >+ status => 404, >+ openapi => { >+ error => 'Patron not found' >+ } >+ ); >+ } >+ >+ return try { >+ >+ my $holds = $c->objects->search( $patron->old_holds ); >+ >+ return $c->render( >+ status => 200, >+ openapi => $holds >+ ); >+ } >+ catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ > > =head3 delete_public > >diff --git a/api/v1/swagger/paths/patrons_holds.yaml b/api/v1/swagger/paths/patrons_holds.yaml >index e8e1335a87..33d7d63f07 100644 >--- a/api/v1/swagger/paths/patrons_holds.yaml >+++ b/api/v1/swagger/paths/patrons_holds.yaml >@@ -60,3 +60,64 @@ > x-koha-authorization: > permissions: > borrowers: edit_borrowers >+"/patrons/{patron_id}/holds/previous": >+ get: >+ x-mojo-to: Patrons::Holds#list_old >+ operationId: getPatronHoldsPrevious >+ tags: >+ - holds >+ summary: List previous holds for a patron >+ parameters: >+ - $ref: "../swagger.yaml#/parameters/patron_id_pp" >+ - $ref: "../swagger.yaml#/parameters/match" >+ - $ref: "../swagger.yaml#/parameters/order_by" >+ - $ref: "../swagger.yaml#/parameters/page" >+ - $ref: "../swagger.yaml#/parameters/per_page" >+ - $ref: "../swagger.yaml#/parameters/q_param" >+ - $ref: "../swagger.yaml#/parameters/q_body" >+ - $ref: "../swagger.yaml#/parameters/request_id_header" >+ - name: x-koha-embed >+ in: header >+ required: false >+ description: Embed list sent as a request header >+ type: array >+ items: >+ type: string >+ enum: >+ - cancellation_requested >+ collectionFormat: csv >+ produces: >+ - application/json >+ responses: >+ "200": >+ description: The patron holds >+ schema: >+ type: array >+ items: >+ $ref: "../swagger.yaml#/definitions/hold" >+ "401": >+ description: Authentication required >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "403": >+ description: Access forbidden >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "404": >+ description: Patron not found >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "500": >+ description: | >+ Internal server error. Possible `error_code` attribute values: >+ >+ * `internal_server_error` >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "503": >+ description: Under maintenance >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ x-koha-authorization: >+ permissions: >+ borrowers: edit_borrowers >diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml >index 46966e40b2..ca0d16d125 100644 >--- a/api/v1/swagger/swagger.yaml >+++ b/api/v1/swagger/swagger.yaml >@@ -419,6 +419,8 @@ paths: > $ref: "./paths/patrons_extended_attributes.yaml#/~1patrons~1{patron_id}~1extended_attributes~1{extended_attribute_id}" > "/patrons/{patron_id}/holds": > $ref: "./paths/patrons_holds.yaml#/~1patrons~1{patron_id}~1holds" >+ "/patrons/{patron_id}/holds/previous": >+ $ref: "./paths/patrons_holds.yaml#/~1patrons~1{patron_id}~1holds~1previous" > "/patrons/{patron_id}/password": > $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password" > "/patrons/{patron_id}/password/expiration_date": >diff --git a/t/db_dependent/api/v1/patrons_holds.t b/t/db_dependent/api/v1/patrons_holds.t >index 98cffc375b..3ed6e6a8da 100755 >--- a/t/db_dependent/api/v1/patrons_holds.t >+++ b/t/db_dependent/api/v1/patrons_holds.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 2; >+use Test::More tests => 3; > use Test::MockModule; > use Test::Mojo; > >@@ -70,6 +70,51 @@ subtest 'list() tests' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'list_old() tests' => sub { >+ >+ plan tests => 9; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object({ >+ class => 'Koha::Patrons', >+ value => { flags => 2 ** 4 } # 'borrowers' flag == 4 >+ }); >+ my $password = 'thePassword123'; >+ $patron->set_password({ password => $password, skip_validation => 1 }); >+ my $userid = $patron->userid; >+ >+ $t->get_ok("//$userid:$password@/api/v1/patrons/" . $patron->id . '/holds/previous') >+ ->status_is( 200, 'SWAGGER3.2.2' ) >+ ->json_is( [] ); >+ >+ my $hold_1 = $builder->build_object({ class => 'Koha::Holds', value => { borrowernumber => $patron->id } }); >+ $hold_1->cancel(); >+ my $cancellationdate = $hold_1->cancellationdate; >+ $cancellationdate =~ s/ \d\d:\d\d:\d\d//; >+ $hold_1->cancellationdate( $cancellationdate ); >+ my $hold_2 = $builder->build_object({ class => 'Koha::Holds', value => { borrowernumber => $patron->id } }); >+ $hold_2->cancel(); >+ $cancellationdate = $hold_2->cancellationdate; >+ $cancellationdate =~ s/ \d\d:\d\d:\d\d//; >+ $hold_2->cancellationdate( $cancellationdate ); >+ >+ $t->get_ok("//$userid:$password@/api/v1/patrons/" . $patron->id . '/holds/previous?_order_by=+me.hold_id') >+ ->status_is( 200, 'SWAGGER3.2.2' ) >+ ->json_is( '' => [ $hold_1->to_api, $hold_2->to_api ], 'Holds retrieved' ); >+ >+ my $non_existent_patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $non_existent_patron_id = $non_existent_patron->id; >+ # get rid of the patron >+ $non_existent_patron->delete; >+ >+ $t->get_ok("//$userid:$password@/api/v1/patrons/" . $non_existent_patron_id . '/holds/previous') >+ ->status_is( 404 ) >+ ->json_is( '/error' => 'Patron not found' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'delete_public() tests' => sub { > > plan tests => 13; >-- >2.30.2
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 35353
:
159055
|
159067
|
163828
|
163829
|
163833
|
163834
|
164298
|
164299