Bugzilla – Attachment 147790 Details for
Bug 33080
Add helpers that return result_set for further processing
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33080: Add small warpper helper to call add_pagination_headers
Bug-33080-Add-small-warpper-helper-to-call-addpagi.patch (text/plain), 3.03 KB, created by
Martin Renvoize (ashimema)
on 2023-03-06 14:39:46 UTC
(
hide
)
Description:
Bug 33080: Add small warpper helper to call add_pagination_headers
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2023-03-06 14:39:46 UTC
Size:
3.03 KB
patch
obsolete
>From 93bf4c9318fdde9df22b0d677f6fb83b8f4fc87c Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 3 Mar 2023 16:51:00 -0300 >Subject: [PATCH] Bug 33080: Add small warpper helper to call > add_pagination_headers > >This patch introduces a small helper that uses the stashed values in >`search_rs` to properly build the pagination headers based on the >resultset. > >To test: >1. Run all the API tests and make sure nothing breaks >2. Run: > $ ktd --shell > $ t/db_dependent/Koha/REST/Plugin/Pagination.t >=> SUCCESS: Tests pass! > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/REST/Plugin/Objects.pm | 45 +++++++++++++++++++++++++++---------- > 1 file changed, 33 insertions(+), 12 deletions(-) > >diff --git a/Koha/REST/Plugin/Objects.pm b/Koha/REST/Plugin/Objects.pm >index 462fdf97da..af0b0b4519 100644 >--- a/Koha/REST/Plugin/Objects.pm >+++ b/Koha/REST/Plugin/Objects.pm >@@ -114,7 +114,10 @@ shouldn't be called twice in it. > 'objects.search' => sub { > my ( $c, $result_set ) = @_; > >- return $c->objects->to_api( $c->objects->search_rs($result_set) ); >+ my $objects_rs = $c->objects->search_rs($result_set); >+ $c->objects->generate_pagination_headers($objects_rs); >+ >+ return $c->objects->to_api( $objects_rs ); > } > ); > >@@ -248,17 +251,8 @@ shouldn't be called twice in it. > my $objects = $result_set->search( $filtered_params, $attributes ); > my $total = $result_set->search->count; > >- $c->add_pagination_headers( >- { >- total => ( >- $objects->is_paged >- ? $objects->pager->total_entries >- : $objects->count >- ), >- base_total => $total, >- params => $args, >- } >- ); >+ $c->stash('koha.pagination.base_total' => $result_set->count); >+ $c->stash('koha.pagination.query_params' => $args); > > return $objects; > } >@@ -293,6 +287,33 @@ Returns the API representation of the passed resultset. > ); > } > ); >+ >+=head3 objects.total_from_resultset >+ >+ my $objects_rs = $objects->search_rs( $rs ); >+ my $api_representation = $c->objects->generate_pagination_headers( $objects_rs ); >+ >+Returns the API representation of the passed resultset. >+ >+=cut >+ >+ $app->helper( >+ 'objects.generate_pagination_headers' => sub { >+ my ( $c, $result_set ) = @_; >+ >+ $c->add_pagination_headers( >+ { >+ total => $c->objects->total_from_resultset( $result_set ), >+ base_total => $c->stash('koha.pagination.base_total'), >+ params => $c->stash('koha.pagination.query_params'), >+ } >+ ); >+ >+ return $result_set->is_paged >+ ? $result_set->pager->total_entries >+ : $result_set->count >+ } >+ ); > } > > 1; >-- >2.39.2
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 33080
:
147469
|
147662
|
147663
|
147720
|
147734
|
147735
|
147736
|
147788
|
147789
|
147790
|
147823
|
147824
|
147825
|
148020
|
148021
|
148022
|
148071
|
148072
|
148073