Bugzilla – Attachment 98201 Details for
Bug 24528
Add a syntax for specifying counts on x-koha-embed
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24528: Add a syntax to x-koha-embed to specify counts
Bug-24528-Add-a-syntax-to-x-koha-embed-to-specify-.patch (text/plain), 2.81 KB, created by
David Nind
on 2020-01-31 06:36:59 UTC
(
hide
)
Description:
Bug 24528: Add a syntax to x-koha-embed to specify counts
Filename:
MIME Type:
Creator:
David Nind
Created:
2020-01-31 06:36:59 UTC
Size:
2.81 KB
patch
obsolete
>From 5d60aa9819a22a7ffee01a53661cb1f66d3a6232 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 29 Jan 2020 09:24:35 -0300 >Subject: [PATCH] Bug 24528: Add a syntax to x-koha-embed to specify counts > >This patch adds a + syntax to specify on the x-koha-embed header that we >want the count of a relation in the response. For example: > >GET /patrons/1 >x-koha-embed: checkouts+count > >Would return a JSON representation of a Koha::Patron, with a new >attribute added: checkouts_count, which will be the result of calling >$patron->checkouts->count. > >This is all done automatically in to_api. This patch makes parsing the >x-koha-embed header build the right structure for passing to the to_api >method. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/Koha/REST/Plugin/Query.t >=> SUCCESS: Tests pass! >3. Sign off :-D > >Sponsored-by: ByWater Solutions > >Signed-off-by: David Nind <david@davidnind.com> > >Signed-off-by: David Nind <david@davidnind.com> >--- > Koha/REST/Plugin/Query.pm | 8 +++++++- > t/Koha/REST/Plugin/Query.t | 9 +++++++-- > 2 files changed, 14 insertions(+), 3 deletions(-) > >diff --git a/Koha/REST/Plugin/Query.pm b/Koha/REST/Plugin/Query.pm >index 769fd0b614..80bdf26216 100644 >--- a/Koha/REST/Plugin/Query.pm >+++ b/Koha/REST/Plugin/Query.pm >@@ -263,7 +263,13 @@ sub _parse_embed { > $result->{$curr} = { children => _parse_embed( $next ) }; > } > else { >- $result->{$curr} = {}; >+ if ( $curr =~ m/^(?<relation>.*)\+count/ ) { >+ my $key = $+{relation} . "_count"; >+ $result->{$key} = { is_count => 1 }; >+ } >+ else { >+ $result->{$curr} = {}; >+ } > } > > return $result; >diff --git a/t/Koha/REST/Plugin/Query.t b/t/Koha/REST/Plugin/Query.t >index 44fc48b8be..a10289ac5b 100644 >--- a/t/Koha/REST/Plugin/Query.t >+++ b/t/Koha/REST/Plugin/Query.t >@@ -140,7 +140,8 @@ get '/stash_embed' => sub { > 'x-koha-embed' => [ > 'checkouts', > 'checkouts.item', >- 'library' >+ 'library', >+ 'holds+count' > ] > } > } >@@ -304,7 +305,7 @@ subtest '_build_query_params_from_api' => sub { > > subtest 'stash_embed() tests' => sub { > >- plan tests => 12; >+ plan tests => 15; > > my $t = Test::Mojo->new; > >@@ -316,6 +317,10 @@ subtest 'stash_embed() tests' => sub { > ->status_is(200) > ->json_is( { checkouts => { children => { item => {} } }, library => {} } ); > >+ $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'holds+count' } ) >+ ->status_is(200) >+ ->json_is( { holds_count => { is_count => 1 } } ); >+ > $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item,patron' } ) > ->status_is(400) > ->json_is( >-- >2.11.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 24528
:
98046
|
98047
|
98065
|
98199
|
98200
|
98201
|
98212
|
98213
|
98214