Bug 32118: Add optional support for `:` as the modifier
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 3 Nov 2022 11:02:21 +0000 (11:02 +0000)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 14 Mar 2023 11:49:27 +0000 (08:49 -0300)
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>
Koha/REST/Plugin/Query.pm
t/Koha/REST/Plugin/Query.t

index 56f2e2b..5ce0da4 100644 (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 };
         }
index 9da2590..4649398 100755 (executable)
@@ -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 => {} } },