From 37a4fc16e56ddb646b1cdbe4390aeb9337d8901f Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 2 Mar 2023 16:41:31 +0000 Subject: [PATCH] Bug 33080: (follow-up) Minor cleanups Whilst reviewing I spotted a few calls to the stash that were no longer required and errors in the POD for the new/updated methods This patch adds fixes for those minor issues. Signed-off-by: Martin Renvoize --- Koha/REST/Plugin/Objects.pm | 45 ++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/Koha/REST/Plugin/Objects.pm b/Koha/REST/Plugin/Objects.pm index 496b7cb886..bb1bded827 100644 --- a/Koha/REST/Plugin/Objects.pm +++ b/Koha/REST/Plugin/Objects.pm @@ -38,10 +38,12 @@ sub register { my $patrons_rs = Koha::Patrons->new; my $patrons = $c->objects->find( $patrons_rs, $id ); + . . . + return $c->render({ status => 200, openapi => $patron }); Performs a database search using given Koha::Objects object and the $id. -Returns I if no object is found Returns the I of +Returns I if no object is found or the I of the requested object. It passes through any embeds if specified. =cut @@ -55,27 +57,27 @@ the requested object. It passes through any embeds if specified. } ); + =head3 objects.find_rs my $patrons_rs = Koha::Patrons->new; - my $patrons = $c->objects->find_rs( $patrons_rs, $id ); + my $patron_rs = $c->objects->find_rs( $patrons_rs, $id ); + . . . + return $c->render({ status => 200, openapi => $patron_rs->to_api }); -Performs a database search using given Koha::Objects object and the $id. +Returns the passed Koha::Objects resultset filtered to the passed $id and +with any embeds requested by the api applied. -Returns a new resultset for further processing. It passes through any embeds if specified. +The resultset can then be used for further processing. =cut $app->helper( 'objects.find_rs' => sub { my ( $c, $result_set, $id ) = @_; - + my $attributes = {}; - - # Look for embeds - my $embed = $c->stash('koha.embed'); - my $strings = $c->stash('koha.strings'); - + # Generate prefetches for embedded stuff $c->dbic_merge_prefetch( { @@ -83,9 +85,9 @@ Returns a new resultset for further processing. It passes through any embeds if result_set => $result_set } ); - + my $object = $result_set->find( $id, $attributes ); - + return $object; } ); @@ -94,8 +96,11 @@ Returns a new resultset for further processing. It passes through any embeds if my $patrons_rs = Koha::Patrons->new; my $patrons = $c->objects->search( $patrons_rs ); + . . . + return $c->render({ status => 200, openapi => $patrons }); -Performs a database search using given Koha::Objects object and query parameters. +Performs a database search using given Koha::Objects object with any api +query parameters applied. Returns an arrayref of the hashrefs representing the resulting objects for API rendering. @@ -108,7 +113,7 @@ shouldn't be called twice in it. $app->helper( 'objects.search' => sub { my ( $c, $result_set ) = @_; - + return $c->objects->to_api( $c->objects->search_rs($result_set) ); } ); @@ -116,11 +121,12 @@ shouldn't be called twice in it. =head3 objects.search_rs my $patrons_rs = Koha::Patrons->new; - my $filtered_patrons_rs = $c->objects->search_rs( $patrons_rs ); - -Performs a database search using given Koha::Objects object and query parameters. + my $patrons_rs = $c->objects->search_rs( $patrons_rs ); + . . . + return $c->render({ status => 200, openapi => $patrons_rs->to_api }); -Returns a new resultset for further processing. +Returns the passed Koha::Objects resultset filtered as requested by the api query +parameters and with requested embeds applied. Warning: this helper adds pagination headers to the calling controller, and thus shouldn't be called twice in it. @@ -138,9 +144,6 @@ shouldn't be called twice in it. my ( $filtered_params, $reserved_params, $path_params ) = $c->extract_reserved_params($args); - # Privileged reques? - my $is_public = $c->stash('is_public'); - # Merge sorting into query attributes $c->dbic_merge_sorting( { -- 2.39.2