[Catalyst-commits] r8113 - in Catalyst-Controller-DBIC-API/1.000/trunk: lib/Catalyst/Controller/DBIC lib/Catalyst/Controller/DBIC/API t/rpc

lukes at dev.catalyst.perl.org lukes at dev.catalyst.perl.org
Sun Jul 13 20:46:34 BST 2008


Author: lukes
Date: 2008-07-13 20:46:34 +0100 (Sun, 13 Jul 2008)
New Revision: 8113

Modified:
   Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API.pm
   Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm
   Catalyst-Controller-DBIC-API/1.000/trunk/t/rpc/list.t
Log:
added list_count attr

Modified: Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm	2008-07-13 18:56:56 UTC (rev 8112)
+++ Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm	2008-07-13 19:46:34 UTC (rev 8113)
@@ -6,7 +6,7 @@
 use base qw/Catalyst::Controller CGI::Expand/;
 
 __PACKAGE__->mk_accessors(qw(
-  class create_requires update_requires update_allows $self->rs_stash_key create_allows list_returns list_grouped_by list_ordered_by rs_stash_key object_stash_key
+  class create_requires update_requires update_allows $self->rs_stash_key create_allows list_count list_returns list_grouped_by list_ordered_by rs_stash_key object_stash_key
 ));
 
 __PACKAGE__->config(
@@ -18,6 +18,7 @@
   list_returns => [],
   list_grouped_by => [],
   list_ordered_by => [],
+  list_count => undef,
   object_stash_key => 'object',
   rs_stash_key => 'class_rs'
 );
@@ -46,16 +47,13 @@
 #  use Data::Dumper; warn Dumper($req_params);
   my $source = $c->stash->{$self->rs_stash_key}->result_source;
 
-  my @default_columns = (scalar(@{$self->list_returns})) ? @{$self->list_returns} : ();
-  my @default_grouped = (scalar(@{$self->list_grouped_by})) ? @{$self->list_grouped_by} : ();
-  my @default_ordered = (scalar(@{$self->list_ordered_by})) ? @{$self->list_ordered_by} : ();
-
   my ($params, $join);
   ($params, $join) = $self->_format_search({ params => $req_params->{search}, source => $source }) if ($req_params->{search});
 
   my $args = {};
   $args->{group_by} = $req_params->{list_grouped_by} || ((scalar(@{$self->list_grouped_by})) ? $self->list_grouped_by : undef);
   $args->{order_by} = $req_params->{list_ordered_by} || ((scalar(@{$self->list_ordered_by})) ? $self->list_ordered_by : undef);
+  $args->{rows} = $req_params->{list_count} || $self->list_count;
   $args->{select} = $req_params->{list_returns} || ((scalar(@{$self->list_returns})) ? $self->list_returns : undef);
   $args->{join} = $join;
 

Modified: Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API.pm	2008-07-13 18:56:56 UTC (rev 8112)
+++ Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API.pm	2008-07-13 19:46:34 UTC (rev 8113)
@@ -78,6 +78,10 @@
 
 Arguments to pass to L<DBIx::Class::ResultSet/order_by> when performing search for L</list>.
 
+=head2 list_count
+
+Arguments to pass to L<DBIx::Class::ResultSet/rows> when performing search for L</list>.
+
 =head2 object_stash_key
 
 Object level methods such as delete and update stash the object in the stash. Specify the stash key you would like to use here. Defaults to 'object'.
@@ -124,7 +128,7 @@
 
 =head2 list
 
-List level action chained from L</setup>. By default populates $c->stash->{response}->{list} with a list of hashrefs representing each object in the class resultset. If the L</list_returns> config param is defined then the hashes will contain only those columns, otherwise all columns in the object will be returned. Similarly L</list_grouped_by> and L</list_ordered_by> affect the ordering and grouping. Note that if list_returns, list_ordered_by or list_grouped_by request parameters are present then these will override the values set on the class.
+List level action chained from L</setup>. By default populates $c->stash->{response}->{list} with a list of hashrefs representing each object in the class resultset. If the L</list_returns> config param is defined then the hashes will contain only those columns, otherwise all columns in the object will be returned. Similarly L</list_count>, L</list_grouped_by> and L</list_ordered_by> affect the maximum number of rows returned as well as the ordering and grouping. Note that if list_returns, list_count, list_ordered_by or list_grouped_by request parameters are present then these will override the values set on the class.
 
 If not all objects in the resultset are required then it's possible to pass conditions to the method as request parameters. L</CGI::Expand> is used to expand the request parameters into a structure and then $c->req->params->{search} is used as the search condition.
 

Modified: Catalyst-Controller-DBIC-API/1.000/trunk/t/rpc/list.t
===================================================================
--- Catalyst-Controller-DBIC-API/1.000/trunk/t/rpc/list.t	2008-07-13 18:56:56 UTC (rev 8112)
+++ Catalyst-Controller-DBIC-API/1.000/trunk/t/rpc/list.t	2008-07-13 19:46:34 UTC (rev 8113)
@@ -10,7 +10,7 @@
 use RestTest;
 use DBICTest;
 use URI;
-use Test::More tests => 17;
+use Test::More tests => 19;
 use Test::WWW::Mechanize::Catalyst 'RestTest';
 use HTTP::Request::Common;
 use JSON::Syck;
@@ -122,3 +122,16 @@
 #  use Data::Dumper; warn Dumper($response, \@expected_response);
   is_deeply( { list => \@expected_response, success => 'true' }, $response, 'correct data returned when everything overridden in query' );
 }
+
+{
+  my $uri = URI->new( $track_list_url );
+  $uri->query_form({ 'list_ordered_by' => 'cd', 'list_count' => 1 });
+  my $req = GET( $uri, 'Accept' => 'text/x-json' );
+  $mech->request($req);
+  cmp_ok( $mech->status, '==', 200, 'search related request okay' );
+
+  my @expected_response = map { { $_->get_columns } } $schema->resultset('Track')->search({}, { group_by => 'position', order_by => 'position ASC', select => 'position', rows => 1 })->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 when everything overridden in query' );
+}




More information about the Catalyst-commits mailing list