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 <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Martin Renvoize 2022-11-03 11:02:21 +00:00 committed by Tomas Cohen Arazi
parent 12e3e91c13
commit 64d3498da4
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
2 changed files with 5 additions and 2 deletions

View File

@ -364,7 +364,7 @@ sub _parse_embed {
$result->{$curr} = { children => _parse_embed( $next ) };
}
else {
if ( $curr =~ m/^(?<relation>.*)\+count/ ) {
if ( $curr =~ m/^(?<relation>.*)[\+|:]count/ ) {
my $key = $+{relation} . "_count";
$result->{$key} = { is_count => 1 };
}

View File

@ -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 => {} } },