[Catalyst-commits] r9295 - in
Catalyst-Controller-DBIC-API/1.001/trunk: .
lib/Catalyst/Controller/DBIC lib/Catalyst/Controller/DBIC/API t/rpc
lukes at dev.catalyst.perl.org
lukes at dev.catalyst.perl.org
Fri Feb 13 16:37:54 GMT 2009
Author: lukes
Date: 2009-02-13 16:37:54 +0000 (Fri, 13 Feb 2009)
New Revision: 9295
Modified:
Catalyst-Controller-DBIC-API/1.001/trunk/
Catalyst-Controller-DBIC-API/1.001/trunk/Changes
Catalyst-Controller-DBIC-API/1.001/trunk/Makefile.PL
Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API.pm
Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm
Catalyst-Controller-DBIC-API/1.001/trunk/t/rpc/list.t
Log:
r10507 at luke-mbp (orig r9291): lukes | 2009-02-13 15:58:50 +0000
new branch
r10508 at luke-mbp (orig r9292): abraxxa | 2009-02-13 16:09:59 +0000
Removed duplicate tests in t/rpc/list.t and t/rest/list.t
Fixed searches on columns which have a rel with the same name and vice versa + tests
Added search by json + test
r10510 at luke-mbp (orig r9294): abraxxa | 2009-02-13 16:36:50 +0000
added docs for json search
Property changes on: Catalyst-Controller-DBIC-API/1.001/trunk
___________________________________________________________________
Name: svk:merge
- 4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Controller-DBIC-API/1.000/trunk:8157
+ 4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Controller-DBIC-API/1.000/trunk:8157
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Controller-DBIC-API/1.001/branches/json_search:9294
Modified: Catalyst-Controller-DBIC-API/1.001/trunk/Changes
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/trunk/Changes 2009-02-13 16:36:50 UTC (rev 9294)
+++ Catalyst-Controller-DBIC-API/1.001/trunk/Changes 2009-02-13 16:37:54 UTC (rev 9295)
@@ -1,5 +1,10 @@
Revision history for Catalyst-Controller-DBIC-API
+1.00199_01
+- Removed duplicate tests in t/rpc/list.t and t/rest/list.t
+- Fixed searches on columns which have a rel with the same name
+ and vice versa + tests
+- Added search by json + test
1.001000
- Added setup_list_method configuration flag (jshirley)
- Added support for setting config params in stash
Modified: Catalyst-Controller-DBIC-API/1.001/trunk/Makefile.PL
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/trunk/Makefile.PL 2009-02-13 16:36:50 UTC (rev 9294)
+++ Catalyst-Controller-DBIC-API/1.001/trunk/Makefile.PL 2009-02-13 16:37:54 UTC (rev 9295)
@@ -8,6 +8,7 @@
requires 'Catalyst::Runtime' => 5.7010;
requires 'Catalyst::Action::REST' => 0.60;
requires 'CGI::Expand' => 2.02;
+requires 'JSON::Any' => 1.19;
build_requires 'Test::More' => 0.7;
build_requires 'Catalyst::Model::DBIC::Schema' => 0.20;
Modified: Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm 2009-02-13 16:36:50 UTC (rev 9294)
+++ Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm 2009-02-13 16:37:54 UTC (rev 9295)
@@ -6,6 +6,7 @@
use base qw/Catalyst::Controller CGI::Expand/;
use DBIx::Class::ResultClass::HashRefInflator;
+use JSON::Any;
__PACKAGE__->mk_accessors(qw(
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 setup_list_method
@@ -55,8 +56,16 @@
my $source = $c->stash->{$self->rs_stash_key}->result_source;
my ($params, $join);
- ($params, $join) = $self->_format_search({ params => $req_params->{search}, source => $source }) if ($req_params->{search});
my $args = {};
+ if (exists $req_params->{search}
+ && ref $req_params->{search} eq 'HASH'
+ ) {
+ ($params, $join) = $self->_format_search({ params => $req_params->{search}, source => $source }) if ($req_params->{search});
+ }
+ # assume json if search wasn't expanded by expand_hash
+ else {
+ $params = exists $c->req->params->{search} ? JSON::Any->from_json($c->req->params->{search}) : undef;
+ }
$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;
Modified: Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API.pm 2009-02-13 16:36:50 UTC (rev 9294)
+++ Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API.pm 2009-02-13 16:37:54 UTC (rev 9295)
@@ -166,11 +166,13 @@
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.
+If not all objects in the resultset are required then it's possible to pass conditions to the method as request parameters. You can use a JSON string as the 'search' parameter for maximum flexibility or use L</CGI::Expand> syntax. In the second case the request parameters are expanded into a structure and then $c->req->params->{search} is used as the search condition.
For example, these request parameters:
?search.name=fred&search.cd.artist=luke
+ OR
+ ?search='{"name":"fred","cd.artist":"luke"}'
Would result in this search (where 'name' is a column of the schema class, 'cd' is a relation of the schema class and 'artist' is a column of the related class):
Modified: Catalyst-Controller-DBIC-API/1.001/trunk/t/rpc/list.t
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/trunk/t/rpc/list.t 2009-02-13 16:36:50 UTC (rev 9294)
+++ Catalyst-Controller-DBIC-API/1.001/trunk/t/rpc/list.t 2009-02-13 16:37:54 UTC (rev 9295)
@@ -61,6 +61,18 @@
}
{
+ my $uri = URI->new( $artist_list_url );
+ $uri->query_form({ 'search' => '{"name":{"LIKE":"%waul%"}}' });
+ my $req = GET( $uri, 'Accept' => 'text/x-json' );
+ $mech->request($req);
+ cmp_ok( $mech->status, '==', 200, 'attempt with basic search okay' );
+
+ my @expected_response = map { { $_->get_columns } } $schema->resultset('Artist')->search({ name => { LIKE => '%waul%' }})->all;
+ my $response = JSON::Syck::Load( $mech->content);
+ is_deeply( { list => \@expected_response, success => 'true' }, $response, 'correct data returned for complex query' );
+}
+
+{
my $uri = URI->new( $producer_list_url );
my $req = GET( $uri, 'Accept' => 'text/x-json' );
$mech->request($req);
More information about the Catalyst-commits
mailing list