From 64d3498da4c62f8a2fa3d28c7cfe8b0a9e251288 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 3 Nov 2022 11:02:21 +0000 Subject: [PATCH] Bug 32118: Add optional support for `:` as the modifier This patch adds optional support for using `:` as the modifier for invoking the 'count' method for relations as discussed. We retain support for `+` for backward compatability to prevent a breaking change. Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/REST/Plugin/Query.pm | 2 +- t/Koha/REST/Plugin/Query.t | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Koha/REST/Plugin/Query.pm b/Koha/REST/Plugin/Query.pm index 56f2e2b0f1..5ce0da42f3 100644 --- a/Koha/REST/Plugin/Query.pm +++ b/Koha/REST/Plugin/Query.pm @@ -364,7 +364,7 @@ sub _parse_embed { $result->{$curr} = { children => _parse_embed( $next ) }; } else { - if ( $curr =~ m/^(?.*)\+count/ ) { + if ( $curr =~ m/^(?.*)[\+|:]count/ ) { my $key = $+{relation} . "_count"; $result->{$key} = { is_count => 1 }; } diff --git a/t/Koha/REST/Plugin/Query.t b/t/Koha/REST/Plugin/Query.t index 9da2590e48..46493987f4 100755 --- a/t/Koha/REST/Plugin/Query.t +++ b/t/Koha/REST/Plugin/Query.t @@ -433,7 +433,7 @@ subtest '_build_query_params_from_api' => sub { subtest 'stash_embed() tests' => sub { - plan tests => 14; + plan tests => 16; my $t = Test::Mojo->new; @@ -446,6 +446,9 @@ subtest 'stash_embed() tests' => sub { $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'holds+count' } ) ->json_is( '/embed' => { holds_count => { is_count => 1 } } ); + $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'holds:count' } ) + ->json_is( '/embed' => { holds_count => { is_count => 1 } } ); + $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item,patron' } ) ->json_is( '/embed' => { checkouts => { children => { item => {} } }, -- 2.39.5