Bugzilla – Attachment 99353 Details for
Bug 24615
Add support for ordering by related object columns in the REST API
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24615: Make object.search helper also order by embedded columns
Bug-24615-Make-objectsearch-helper-also-order-by-e.patch (text/plain), 4.21 KB, created by
Martin Renvoize (ashimema)
on 2020-02-21 07:23:51 UTC
(
hide
)
Description:
Bug 24615: Make object.search helper also order by embedded columns
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2020-02-21 07:23:51 UTC
Size:
4.21 KB
patch
obsolete
>From 014e11c04fa5be04389130e15ab49ed8f4734e4d Mon Sep 17 00:00:00 2001 >From: Agustin Moyano <agustinmoyano@theke.io> >Date: Fri, 7 Feb 2020 23:54:14 -0300 >Subject: [PATCH] Bug 24615: Make object.search helper also order by embedded > columns > >With this patch REST API request can order results by embedded columns. > >Full path to the column must be given for it to work. >For example: If you are on biblio endpoint and you want to order by holding patron's card number you could > >> GET /biblio/1?_order_by=item.holds.cardnumber HTTP/1.1 >> x-koha-embed: item.holds > >To test: >1. apply this patch >2. prove t/db_dependent/Koha/REST/Plugin/Objects.t > >Signed-off-by: David Nind <david@davidnind.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/REST/Plugin/Query.pm | 2 +- > t/db_dependent/Koha/REST/Plugin/Objects.t | 29 ++++++++++++++++++----- > 2 files changed, 24 insertions(+), 7 deletions(-) > >diff --git a/Koha/REST/Plugin/Query.pm b/Koha/REST/Plugin/Query.pm >index 06e8b5d256..73e5d79f07 100644 >--- a/Koha/REST/Plugin/Query.pm >+++ b/Koha/REST/Plugin/Query.pm >@@ -277,7 +277,7 @@ sub _build_order_atom { > my $param = $string; > $param =~ s/^(\+|\-|\s)//; > if ( $result_set ) { >- my $model_param = $result_set->from_api_mapping->{$param}; >+ my $model_param = _from_api_param($param, $result_set); > $param = $model_param if defined $model_param; > } > >diff --git a/t/db_dependent/Koha/REST/Plugin/Objects.t b/t/db_dependent/Koha/REST/Plugin/Objects.t >index 32cfd5d699..386d3ec467 100644 >--- a/t/db_dependent/Koha/REST/Plugin/Objects.t >+++ b/t/db_dependent/Koha/REST/Plugin/Objects.t >@@ -72,12 +72,12 @@ get '/biblios' => sub { > } > }); > my $biblios = $c->objects->search($biblios_set); >- >- $c->render( status => 200, json => {count => scalar(@$biblios)} ); >+ $c->render( status => 200, json => {count => scalar(@$biblios), biblios => $biblios} ); > }; > >+ > # The tests >-use Test::More tests => 8; >+use Test::More tests => 9; > use Test::Mojo; > > use t::lib::TestBuilder; >@@ -316,8 +316,8 @@ subtest 'object.search helper with all query methods' => sub { > > $schema->storage->txn_begin; > >- my $patron1 = $builder->build_object( { class => "Koha::Patrons" , value => {cardnumber => 'cardpatron1', firstname=>'patron1'} } ); >- my $patron2 = $builder->build_object( { class => "Koha::Patrons" , value => {cardnumber => 'cardpatron2', firstname=>'patron2'} } ); >+ my $patron1 = $builder->build_object( { class => "Koha::Patrons" , value => {firstname=>'patron1'} } ); >+ my $patron2 = $builder->build_object( { class => "Koha::Patrons" , value => {firstname=>'patron2'} } ); > my $biblio1 = $builder->build_sample_biblio; > my $biblio2 = $builder->build_sample_biblio; > my $biblio3 = $builder->build_sample_biblio; >@@ -335,4 +335,21 @@ subtest 'object.search helper with all query methods' => sub { > ->json_is('/count' => 0, 'there shouldn\'t be biblios where suggester has patron1 fistname and patron2 id'); > > $schema->storage->txn_rollback; >-}; >\ No newline at end of file >+}; >+ >+subtest 'object.search helper order by embedded columns' => sub { >+ plan tests => 3; >+ >+ my $patron1 = $builder->build_object( { class => "Koha::Patrons" , value => {firstname=>'patron1'} } ); >+ my $patron2 = $builder->build_object( { class => "Koha::Patrons" , value => {firstname=>'patron2'} } ); >+ my $biblio1 = $builder->build_sample_biblio; >+ my $biblio2 = $builder->build_sample_biblio; >+ my $suggestion1 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron1->borrowernumber, biblionumber => $biblio1->biblionumber} } ); >+ my $suggestion2 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio2->biblionumber} } ); >+ >+ $t->get_ok('/biblios?_order_by=-suggestions.suggester.firstname' => json => [{"me.biblio_id" => $biblio1->biblionumber}, {"me.biblio_id" => $biblio2->biblionumber}]) >+ ->json_is('/biblios/0/biblio_id' => $biblio2->biblionumber, 'Biblio 2 should be first') >+ ->json_is('/biblios/1/biblio_id' => $biblio1->biblionumber, 'Biblio 1 should be second'); >+ >+ $schema->storage->txn_begin; >+} >\ No newline at end of file >-- >2.20.1
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 24615
:
98604
|
99338
| 99353