From 5ed3758b97aa1dee2fb2b4bb574d89a3b2f318e9 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 3 Nov 2023 10:51:07 -0300 Subject: [PATCH] Bug 29002: (QA follow-up) Correct param retrieval in controllers Signed-off-by: Tomas Cohen Arazi --- Koha/REST/V1/Bookings.pm | 23 +++++++++++------------ Koha/REST/V1/Items.pm | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Koha/REST/V1/Bookings.pm b/Koha/REST/V1/Bookings.pm index 08a772f50e..f4e15013ef 100644 --- a/Koha/REST/V1/Bookings.pm +++ b/Koha/REST/V1/Bookings.pm @@ -37,13 +37,11 @@ sub list { my $c = shift->openapi->valid_input or return; return try { - my $bookings_set = Koha::Bookings->new; - my $bookings = $c->objects->search($bookings_set); + my $bookings = $c->objects->search( Koha::Bookings->new ); return $c->render( status => 200, openapi => $bookings ); } catch { $c->unhandled_exception($_); }; - } =head3 get @@ -56,7 +54,7 @@ sub get { my $c = shift->openapi->valid_input or return; return try { - my $booking = Koha::Bookings->find( $c->validation->param('booking_id') ); + my $booking = $c->objects->find( Koha::Bookings->new, $c->param('booking_id') ); unless ($booking) { return $c->render( status => 404, @@ -64,7 +62,7 @@ sub get { ); } - return $c->render( status => 200, openapi => $booking->to_api ); + return $c->render( status => 200, openapi => $booking ); } catch { $c->unhandled_exception($_); } @@ -80,12 +78,12 @@ sub add { my $c = shift->openapi->valid_input or return; return try { - my $booking = Koha::Booking->new_from_api( $c->validation->param('body') ); + my $booking = Koha::Booking->new_from_api( $c->req->json ); $booking->store; $c->res->headers->location( $c->req->url->to_string . '/' . $booking->booking_id ); return $c->render( status => 201, - openapi => $booking->to_api + openapi => $c->objects->to_api( $booking ), ); } catch { if ( blessed $_ and $_->isa('Koha::Exceptions::Booking::Clash') ) { @@ -108,7 +106,7 @@ Controller function that handles updating an existing booking sub update { my $c = shift->openapi->valid_input or return; - my $booking = Koha::Bookings->find( $c->validation->param('booking_id') ); + my $booking = $c->objects->find_rs( Koha::Bookings->new, $c->param('booking_id') ); if ( not defined $booking ) { return $c->render( @@ -118,9 +116,9 @@ sub update { } return try { - $booking->set_from_api( $c->validation->param('body') ); + $booking->set_from_api( $c->req->json ); $booking->store(); - return $c->render( status => 200, openapi => $booking->to_api ); + return $c->render( status => 200, openapi => $c->objects->to_api($booking) ); } catch { $c->unhandled_exception($_); }; @@ -135,8 +133,9 @@ Controller function that handles removing an existing booking sub delete { my $c = shift->openapi->valid_input or return; - my $booking = Koha::Bookings->find( $c->validation->param('booking_id') ); - if ( not defined $booking ) { + my $booking = Koha::Bookings->find( $c->param('booking_id') ); + + unless ( $booking ) { return $c->render( status => 404, openapi => { error => "Object not found" } diff --git a/Koha/REST/V1/Items.pm b/Koha/REST/V1/Items.pm index 736c0ebef6..5db12b669d 100644 --- a/Koha/REST/V1/Items.pm +++ b/Koha/REST/V1/Items.pm @@ -183,7 +183,7 @@ Controller function that handles retrieving item's bookings sub get_bookings { my $c = shift->openapi->valid_input or return; - my $item = Koha::Items->find( { itemnumber => $c->validation->param('item_id') }, { prefetch => ['bookings'] } ); + my $item = Koha::Items->find( { itemnumber => $c->param('item_id') }, { prefetch => ['bookings'] } ); unless ($item) { return $c->render( -- 2.39.2