From c7ecae0595725c8e7b4842f98738c3d229a9ce41 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 25 Jan 2021 10:35:20 -0300 Subject: [PATCH] Bug 27544: Simplilfy GET /checkouts implementation This patch makes the list() controller method simpler, by removing the checked_in parameter, and passing the appropriate restulset. To test: 1. Run: $ kshell k$ prove t/db_dependent/api/v1/checkouts.t => SUCCESS: Tests pass! 2. Apply this patch 3. Repeat (1) => SUCCESS: Tests still pass! (no behaviour change) 4. Sign off :-D Signed-off-by: Tomas Cohen Arazi --- Koha/REST/V1/Checkouts.pm | 47 +++++---------------------------------- 1 file changed, 5 insertions(+), 42 deletions(-) diff --git a/Koha/REST/V1/Checkouts.pm b/Koha/REST/V1/Checkouts.pm index 93feeaeb24f..8fc07181b11 100644 --- a/Koha/REST/V1/Checkouts.pm +++ b/Koha/REST/V1/Checkouts.pm @@ -45,7 +45,7 @@ List Koha::Checkout objects sub list { my $c = shift->openapi->valid_input or return; - my $checked_in = $c->validation->param('checked_in'); + my $checked_in = delete $c->validation->output->{checked_in}; try { my $checkouts_set; @@ -56,49 +56,12 @@ sub list { $checkouts_set = Koha::Checkouts->new; } - my $args = $c->validation->output; - my $attributes = {}; + my $checkouts = $c->objects->search( $checkouts_set ); - # Extract reserved params - my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($args); - - # Merge sorting into query attributes - $c->dbic_merge_sorting( - { - attributes => $attributes, - params => $reserved_params, - result_set => $checkouts_set - } - ); - - # Merge pagination into query attributes - $c->dbic_merge_pagination( - { - filter => $attributes, - params => $reserved_params - } + return $c->render( + status => 200, + openapi => $checkouts ); - - # Call the to_model function by reference, if defined - if ( defined $filtered_params ) { - # remove checked_in - delete $filtered_params->{checked_in}; - # Apply the mapping function to the passed params - $filtered_params = $checkouts_set->attributes_from_api($filtered_params); - $filtered_params = $c->build_query_params( $filtered_params, $reserved_params ); - } - - # Perform search - my $checkouts = $checkouts_set->search( $filtered_params, $attributes ); - - if ($checkouts->is_paged) { - $c->add_pagination_headers({ - total => $checkouts->pager->total_entries, - params => $args, - }); - } - - return $c->render( status => 200, openapi => $checkouts->to_api ); } catch { $c->unhandled_exception($_); }; -- 2.30.0