Bugzilla – Attachment 85866 Details for
Bug 22206
Add routes to enable suspension or resumption of holds
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22206: Add routes to suspend/resume holds
Bug-22206-Add-routes-to-suspendresume-holds.patch (text/plain), 3.11 KB, created by
Josef Moravec
on 2019-02-28 13:21:41 UTC
(
hide
)
Description:
Bug 22206: Add routes to suspend/resume holds
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2019-02-28 13:21:41 UTC
Size:
3.11 KB
patch
obsolete
>From 7471ea6a0a2c24f71ea2540f877ddbb980a6bd31 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 28 Jan 2019 07:40:15 -0300 >Subject: [PATCH] Bug 22206: Add routes to suspend/resume holds > >This patch introduces: > >- POST /holds/{hold_id}/suspension { "expiration_date": "2019-01-30" } >- DELETE /holds/{hold_id}/suspension > >to suspend a hold or resume a suspended hold, respectively. > >To test: >- Apply this patches >- Run: > $ kshell > k$ prove t/db_dependent/api/v1/holds.t >=> SUCCESS: Tests pass! >- Sign off :-D > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >--- > Koha/REST/V1/Holds.pm | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 76 insertions(+) > >diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm >index a899e43a5e..190a57ef3d 100644 >--- a/Koha/REST/V1/Holds.pm >+++ b/Koha/REST/V1/Holds.pm >@@ -272,6 +272,82 @@ sub delete { > return $c->render( status => 200, openapi => {} ); > } > >+=head3 suspend >+ >+Method that handles suspending a hold >+ >+=cut >+ >+sub suspend { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $hold_id = $c->validation->param('hold_id'); >+ my $hold = Koha::Holds->find($hold_id); >+ my $body = $c->req->json; >+ my $exp_date = ($body) ? $body->{expiration_date} : undef; >+ >+ unless ($hold) { >+ return $c->render( status => 404, openapi => { error => 'Hold not found.' } ); >+ } >+ >+ return try { >+ my $date = ($exp_date) ? dt_from_string( $exp_date, 'rfc3339' ) : undef; >+ $hold->suspend_hold($date); >+ $hold->discard_changes; >+ $c->res->headers->location( $c->req->url->to_string ); >+ return $c->render( >+ status => 201, >+ openapi => { >+ expiration_date => output_pref( >+ { dt => dt_from_string( $hold->suspend_until ), >+ dateformat => 'rfc3339', >+ dateonly => 1 >+ } >+ ) >+ } >+ ); >+ } >+ catch { >+ if ( blessed $_ and $_->isa('Koha::Exceptions::Hold::CannotSuspendFound') ) { >+ return $c->render( status => 400, openapi => { error => "$_" } ); >+ } >+ else { >+ return $c->render( >+ status => 500, >+ openapi => { error => "Something went wrong. check the logs." } >+ ); >+ } >+ }; >+} >+ >+=head3 resume >+ >+Method that handles resuming a hold >+ >+=cut >+ >+sub resume { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $hold_id = $c->validation->param('hold_id'); >+ my $hold = Koha::Holds->find($hold_id); >+ my $body = $c->req->json; >+ >+ unless ($hold) { >+ return $c->render( status => 404, openapi => { error => 'Hold not found.' } ); >+ } >+ >+ return try { >+ $hold->resume; >+ return $c->render( status => 204, openapi => {} ); >+ } >+ catch { >+ return $c->render( >+ status => 500, >+ openapi => { error => "Something went wrong. check the logs." } >+ ); >+ }; >+} > > =head3 _to_api > >-- >2.11.0
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 22206
:
84473
|
84474
|
84475
|
85056
|
85057
|
85058
|
85468
|
85469
|
85470
|
85471
|
85862
|
85864
|
85865
| 85866 |
85867
|
85868