Bugzilla – Attachment 152985 Details for
Bug 33974
Add ability to search biblios endpoint using any biblioitem attribute
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33974: (follow-up) Adapt the orders endpoint
Bug-33974-follow-up-Adapt-the-orders-endpoint.patch (text/plain), 6.30 KB, created by
Martin Renvoize (ashimema)
on 2023-07-03 15:27:19 UTC
(
hide
)
Description:
Bug 33974: (follow-up) Adapt the orders endpoint
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2023-07-03 15:27:19 UTC
Size:
6.30 KB
patch
obsolete
>From 390bbf81d0ada7e9234593e6a2e0526bb72ea43e Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 16 Jun 2023 12:53:05 -0300 >Subject: [PATCH] Bug 33974: (follow-up) Adapt the orders endpoint > >In order to reduce the technical debt carried on the orders controller, >and to highlight the decisions made on the prior patch, I adapted the >list() orders controller using the new tools in town. > >The result is this endpoint can now embed bibio, without needing to have >a custom piece of code. > >To test: >1. Apply this patch >2. Run: > $ ktd --shell > k$ prove t/db_dependent/api/v1/*.t >=> SUCCESS: Tests pass :-D > >Signed-off-by: Sam Lau <samalau@gmail.com> >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/REST/V1/Acquisitions/Orders.pm | 127 ++-------------------------- > 1 file changed, 5 insertions(+), 122 deletions(-) > >diff --git a/Koha/REST/V1/Acquisitions/Orders.pm b/Koha/REST/V1/Acquisitions/Orders.pm >index bb12ed0a53..0effcc5cac 100644 >--- a/Koha/REST/V1/Acquisitions/Orders.pm >+++ b/Koha/REST/V1/Acquisitions/Orders.pm >@@ -61,139 +61,22 @@ sub list { > $orders_rs = $orders_rs->filter_by_id_including_transfers({ ordernumber => $order_id }) > if $order_id; > >- my $args = $c->validation->output; >- my $attributes = {}; >+ my @query_fixers; > >- # Extract reserved params >- my ( $filtered_params, $reserved_params, $path_params ) = $c->extract_reserved_params($args); > # Look for embeds > my $embed = $c->stash('koha.embed'); >- my $fixed_embed = clone($embed); >- if ( exists $fixed_embed->{biblio} ) { >+ if ( exists $embed->{biblio} ) { # asked to embed biblio >+ my $fixed_embed = clone($embed); > # Add biblioitems to prefetch > # FIXME remove if we merge biblio + biblioitems > $fixed_embed->{biblio}->{children}->{biblioitem} = {}; > $c->stash('koha.embed', $fixed_embed); >+ push @query_fixers, (sub{ Koha::Biblios->new->api_query_fixer( $_[0], 'biblio', $_[1] ) }); > } > >- if ( exists $reserved_params->{_order_by} ) { >- # _order_by passed, fix if required >- for my $p ( @{$reserved_params->{_order_by}} ) { >- $p = $c->table_name_fixer($p); >- } >- } >- >- # Merge sorting into query attributes >- $c->dbic_merge_sorting( >- { >- attributes => $attributes, >- params => $reserved_params, >- result_set => $orders_rs, >- } >- ); >- >- # If no pagination parameters are passed, default >- $reserved_params->{_per_page} //= C4::Context->preference('RESTdefaultPageSize'); >- $reserved_params->{_page} //= 1; >- >- unless ( $reserved_params->{_per_page} == -1 ) { >- # Merge pagination into query attributes >- $c->dbic_merge_pagination( >- { >- filter => $attributes, >- params => $reserved_params >- } >- ); >- } >- >- # Generate prefetches for embedded stuff >- $c->dbic_merge_prefetch( >- { >- attributes => $attributes, >- result_set => $orders_rs >- } >- ); >- >- # Call the to_model function by reference, if defined >- if ( defined $filtered_params ) { >- >- # Apply the mapping function to the passed params >- $filtered_params = $orders_rs->attributes_from_api($filtered_params); >- $filtered_params = $c->build_query_params( $filtered_params, $reserved_params ); >- } >- >- if ( defined $path_params ) { >- >- # Apply the mapping function to the passed params >- $filtered_params //= {}; >- $path_params = $orders_rs->attributes_from_api($path_params); >- foreach my $param (keys %{$path_params}) { >- $filtered_params->{$param} = $path_params->{$param}; >- } >- } >- >- if ( defined $reserved_params->{q} >- || defined $reserved_params->{query} >- || defined $reserved_params->{'x-koha-query'} ) >- { >- >- $filtered_params //={}; >- >- my @query_params_array; >- >- my $json = JSON->new; >- >- # q is defined as multi => JSON::Validator generates an array >- # containing the string >- foreach my $q ( @{ $reserved_params->{q} } ) { >- push @query_params_array, >- $json->decode( $c->table_name_fixer($q) ) >- if $q; # skip if exists but is empty >- } >- >- # x-koha-query contains a string >- push @query_params_array, >- $json->decode( >- $c->table_name_fixer( $reserved_params->{'x-koha-query'} ) ) >- if $reserved_params->{'x-koha-query'}; >- >- # query is already decoded by JSON::Validator at this point >- push @query_params_array, >- $json->decode( >- $c->table_name_fixer( >- $json->encode( $reserved_params->{query} ) >- ) >- ) if $reserved_params->{query}; >- >- my $query_params; >- >- if ( scalar(@query_params_array) > 1 ) { >- $query_params = { '-and' => \@query_params_array }; >- } >- else { >- $query_params = $query_params_array[0]; >- } >- >- $filtered_params = $c->merge_q_params( $filtered_params, $query_params, $orders_rs ); >- } >- >- # Perform search >- my $orders = $orders_rs->search( $filtered_params, $attributes ); >- my $total = $orders_rs->search->count; >- >- $c->add_pagination_headers( >- { >- base_total => $total, >- page => $reserved_params->{_page}, >- per_page => $reserved_params->{_per_page}, >- query_params => $args, >- total => ( $orders->is_paged ? $orders->pager->total_entries : $orders->count ), >- } >- ); >- > return $c->render( > status => 200, >- openapi => $c->objects->to_api($orders) >+ openapi => $c->objects->search( $orders_rs, \@query_fixers ), > ); > } > catch { >-- >2.41.0
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 33974
:
152433
|
152434
|
152435
|
152487
|
152488
|
152489
|
152765
|
152766
|
152767
|
152983
|
152984
| 152985 |
152986
|
152988
|
153104