From 1a1e011942b566a8e5a2534bd6e04dc1697edbad Mon Sep 17 00:00:00 2001 From: Hammat Wele Date: Wed, 15 Mar 2023 21:22:56 +0000 Subject: [PATCH] Bug 25870: (follow-up) Adding pagination information on the headers, returns an empty result when the query is empty --- Koha/REST/V1/Biblios.pm | 30 ++++++++++++++++++------------ api/v1/swagger/paths/biblios.yaml | 3 +++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm index bff93b279e..fe6294d6c6 100644 --- a/Koha/REST/V1/Biblios.pm +++ b/Koha/REST/V1/Biblios.pm @@ -161,24 +161,18 @@ sub get_biblios_public { my ( $error, $results, $total_hits ) = $searcher->simple_search_compat( $query, 0, undef ); - if ( !$total_hits ) { - return $c->render( - status => 404, - openapi => { error => 'Nothing found.' } - ); - } - return try { my $patron = $c->stash('koha.user'); my $is_public = $c->stash('is_public'); my $opachiddenitems_rules = C4::Context->yaml_preference('OpacHiddenItems'); - my $searchengine = C4::Context->preference('SearchEngine'); - my @biblionumbers - = $searchengine eq 'Zebra' - ? map { MARC::Record->new_from_xml( $_, 'UTF-8' )->field('999')->subfield('c') } $results->@* - : map { $_->field('999')->subfield('c') } $results->@*; + my @biblionumbers; + foreach my $res ( @$results ) { + my $bibno = $searcher->extract_biblionumber( $res ); + push @biblionumbers, $bibno if $bibno; + } + my @biblios = map { Koha::Biblios->find( { biblionumber => $_ } ) } @biblionumbers; my @records = map { next if ( $is_public @@ -187,6 +181,18 @@ sub get_biblios_public { $_->metadata->record; } @biblios; + # Extract reserved params + my ( $filtered_params, $reserved_params, $path_params ) = $c->extract_reserved_params( $c->req->params->to_hash ); + + $c->add_pagination_headers( + { + page => $reserved_params->{_page}, + per_page => $reserved_params->{_per_page}, + query_params => $reserved_params->{_q_params}, + total => $total_hits, + } + ); + $c->respond_to( mij => { status => 200, diff --git a/api/v1/swagger/paths/biblios.yaml b/api/v1/swagger/paths/biblios.yaml index 0c3dc6e62a..3e048f2299 100644 --- a/api/v1/swagger/paths/biblios.yaml +++ b/api/v1/swagger/paths/biblios.yaml @@ -463,6 +463,9 @@ summary: Get biblios (public) parameters: - $ref: "../swagger.yaml#/parameters/q_ccl" + - $ref: "../swagger.yaml#/parameters/page" + - $ref: "../swagger.yaml#/parameters/per_page" + - $ref: "../swagger.yaml#/parameters/q_param" produces: - application/marc-in-json responses: -- 2.34.1