Bugzilla – Attachment 98065 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.71 KB, created by
Tomás Cohen Arazi (tcohen)
on 2020-01-29 12:33:34 UTC
(
hide
)
Description:
Bug 24528: Add a syntax to x-koha-embed to specify counts
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2020-01-29 12:33:34 UTC
Size:
2.71 KB
patch
obsolete
>From 546e82df3e37065b790f356caf7263a3724fbc88 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 >--- > 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 b2ebd8f77a..62c881afcb 100644 >--- a/Koha/REST/Plugin/Query.pm >+++ b/Koha/REST/Plugin/Query.pm >@@ -258,7 +258,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 fa69b55848..1a212614e0 100644 >--- a/t/Koha/REST/Plugin/Query.t >+++ b/t/Koha/REST/Plugin/Query.t >@@ -150,7 +150,8 @@ get '/stash_embed' => sub { > 'x-koha-embed' => [ > 'checkouts', > 'checkouts.item', >- 'library' >+ 'library', >+ 'holds+count' > ] > } > } >@@ -309,7 +310,7 @@ subtest '_build_query_params_from_api' => sub { > > subtest 'stash_embed() tests' => sub { > >- plan tests => 12; >+ plan tests => 15; > > my $t = Test::Mojo->new; > >@@ -321,6 +322,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.25.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