[Catalyst-commits] r10937 - in Catalyst-Controller-DBIC-API/1.003/trunk: . lib/Catalyst/Controller/DBIC lib/Catalyst/Controller/DBIC/API t/rpc

abraxxa at dev.catalyst.perl.org abraxxa at dev.catalyst.perl.org
Tue Jul 21 17:02:02 GMT 2009


Author: abraxxa
Date: 2009-07-21 17:02:01 +0000 (Tue, 21 Jul 2009)
New Revision: 10937

Modified:
   Catalyst-Controller-DBIC-API/1.003/trunk/Changes
   Catalyst-Controller-DBIC-API/1.003/trunk/lib/Catalyst/Controller/DBIC/API.pm
   Catalyst-Controller-DBIC-API/1.003/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm
   Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list.t
Log:
added totalcount to paged list responses
fixed some tests weren't run in t/rpc/list.t
fixed wrong setup_dbic_args_method error message


Modified: Catalyst-Controller-DBIC-API/1.003/trunk/Changes
===================================================================
--- Catalyst-Controller-DBIC-API/1.003/trunk/Changes	2009-07-21 15:39:10 UTC (rev 10936)
+++ Catalyst-Controller-DBIC-API/1.003/trunk/Changes	2009-07-21 17:02:01 UTC (rev 10937)
@@ -1,5 +1,10 @@
 Revision history for Catalyst-Controller-DBIC-API
 
+1.003002
+- Added totalcount to paged list responses
+- Fixed some tests weren't run in t/rpc/list.t
+- Fixed wrong setup_dbic_args_method error message
+
 1.003001
 - Minor fix to prevent failing test
 

Modified: Catalyst-Controller-DBIC-API/1.003/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.003/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm	2009-07-21 15:39:10 UTC (rev 10936)
+++ Catalyst-Controller-DBIC-API/1.003/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm	2009-07-21 17:02:01 UTC (rev 10937)
@@ -72,6 +72,9 @@
 	return if $self->get_errors($c);
 
 	$c->stash->{$self->rs_stash_key} = $c->stash->{$self->rs_stash_key}->search($params, $args);
+    # add the total count of all rows in case of a paged resultset
+    $c->stash->{_dbic_api}->{totalcount} = $c->stash->{$self->rs_stash_key}->pager->total_entries
+        if $args->{page};
 	$c->forward('format_list');
 }
 
@@ -96,12 +99,12 @@
 		}
 	}
 
-	if ( my $a = $self->setup_list_method ) {
-		my $setup_action = $self->action_for($a);
+	if ( my $action_name = $self->setup_list_method ) {
+		my $setup_action = $self->action_for($action_name);
 		if ( defined $setup_action ) {
 			$c->forward("/$setup_action", [ $req_params ]);
 		} else {
-			$c->log->error("setup_list_method was configured, but action $a not found");
+			$c->log->error("setup_list_method was configured, but action $action_name not found");
 		}
 	}
 	my $source = $c->stash->{$self->rs_stash_key}->result_source;
@@ -138,12 +141,12 @@
 		$args->{select} = [map { ($_ =~ m/\./) ? $_ : "me.$_" } (ref $args->{select}) ? @{$args->{select}} : $args->{select}];
 	}
 	$args->{join} = $join;
-	if ( my $action = $self->setup_dbic_args_method ) {
-		my $format_action = $self->action_for($action);
+	if ( my $action_name = $self->setup_dbic_args_method ) {
+		my $format_action = $self->action_for($action_name);
 		if ( defined $format_action ) {
 			($params, $args) = @{$c->forward("/$format_action", [ $params, $args ])};
 		} else {
-			$c->log->error("setup_dbic_args_method was configured, but action $a not found");
+			$c->log->error("setup_dbic_args_method was configured, but action $action_name not found");
 		}
 	}
 	
@@ -222,6 +225,11 @@
 	my $rs = $c->stash->{$self->rs_stash_key}->search;
 	$rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
 	$c->stash->{response}->{list} = [ $rs->all ];
+    if (my $totalcount = $c->stash->{_dbic_api}->{totalcount}) {
+        # numify which is important for JSON
+        $totalcount += 0;
+        $c->stash->{response}->{totalcount} = $totalcount;
+    }
 }
 
 sub create :Private {

Modified: Catalyst-Controller-DBIC-API/1.003/trunk/lib/Catalyst/Controller/DBIC/API.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.003/trunk/lib/Catalyst/Controller/DBIC/API.pm	2009-07-21 15:39:10 UTC (rev 10936)
+++ Catalyst-Controller-DBIC-API/1.003/trunk/lib/Catalyst/Controller/DBIC/API.pm	2009-07-21 17:02:01 UTC (rev 10937)
@@ -9,7 +9,7 @@
 
 =cut
 
-our $VERSION = '1.003001';
+our $VERSION = '1.003002';
 
 =head1 NAME
 

Modified: Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list.t
===================================================================
--- Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list.t	2009-07-21 15:39:10 UTC (rev 10936)
+++ Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list.t	2009-07-21 17:02:01 UTC (rev 10937)
@@ -60,7 +60,6 @@
 	is_deeply( { list => \@expected_response, success => 'true' }, $response, 'correct data returned for complex query' );
 }
 
-exit;
 {
 	my $uri = URI->new( $producer_list_url );
 	my $req = GET( $uri, 'Accept' => 'text/x-json' );
@@ -156,7 +155,7 @@
 	my @expected_response = map { { $_->get_columns } } $schema->resultset('Track')->search({}, { group_by => 'position', order_by => 'position ASC', select => 'position', rows => 2, page => 2 })->all;
 	my $response = JSON::Syck::Load( $mech->content);
 	#  use Data::Dumper; warn Dumper($response, \@expected_response);
-	is_deeply( { list => \@expected_response, success => 'true' }, $response, 'correct data returned' );
+    is_deeply( { list => \@expected_response, success => 'true', totalcount => 3 }, $response, 'correct data returned' );
 }
 
 {




More information about the Catalyst-commits mailing list