From 222b7b37f7780b9f8b357e02e2c2262eed7dbec3 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 3 Sep 2019 16:39:40 -0300 Subject: [PATCH] Bug 23517: Add the controller method for holds priorities handling This patch implements the PUT /holds/:hold_id/priority endpoint 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: Tomas Cohen Arazi Signed-off-by: Owen Leonard Signed-off-by: Josef Moravec Signed-off-by: Liz Rea Signed-off-by: Martin Renvoize --- Koha/REST/V1/Holds.pm | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm index a74307ff72..5ccc1fde35 100644 --- a/Koha/REST/V1/Holds.pm +++ b/Koha/REST/V1/Holds.pm @@ -349,6 +349,46 @@ sub resume { }; } +=head3 update_priority + +Method that handles modifying a Koha::Hold object + +=cut + +sub update_priority { + my $c = shift->openapi->valid_input or return; + + my $hold_id = $c->validation->param('hold_id'); + my $hold = Koha::Holds->find($hold_id); + + unless ($hold) { + return $c->render( + status => 404, + openapi => { error => "Hold not found" } + ); + } + + return try { + my $priority = $c->req->json; + C4::Reserves::_FixPriority( + { + reserve_id => $hold_id, + rank => $priority + } + ); + + return $c->render( status => 200, openapi => $priority ); + } + catch { + return $c->render( + status => 500, + openapi => { error => "Something went wrong. check the logs." } + ); + }; +} + +=head2 Internal methods + =head3 _to_api Helper function that maps unblessed Koha::Hold objects into REST api -- 2.39.5