X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=blobdiff_plain;f=lib%2FCatalyst%2FController%2FDBIC%2FAPI.pm;h=89aca6263d392c903e27d17ce033da453f716c11;hp=7ae2bc338141f25cb60bcbed5aa52f5dfbc34d8f;hb=3300302344139421414886ed813a5376e8ff42ee;hpb=d666a194afbf36c50785acff4e7fb4e04e534374 diff --git a/lib/Catalyst/Controller/DBIC/API.pm b/lib/Catalyst/Controller/DBIC/API.pm index 7ae2bc3..89aca62 100644 --- a/lib/Catalyst/Controller/DBIC/API.pm +++ b/lib/Catalyst/Controller/DBIC/API.pm @@ -221,7 +221,7 @@ sub deserialize :ActionClass('Deserialize') { $req_params = CGI::Expand->expand_hash($c->req->params); - foreach my $param (@{[$self->search_arg, $self->count_arg, $self->page_arg, $self->ordered_by_arg, $self->grouped_by_arg, $self->prefetch_arg]}) + foreach my $param (@{[$self->search_arg, $self->count_arg, $self->page_arg, $self->offset_arg, $self->ordered_by_arg, $self->grouped_by_arg, $self->prefetch_arg]}) { # these params can also be composed of JSON # but skip if the parameter is not provided @@ -369,7 +369,12 @@ sub list_perform_search $req->_set_current_result_set($rs); $req->_set_search_total_entries($req->current_result_set->pager->total_entries) - if $req->has_search_attributes && $req->search_attributes->{page}; + if $req->has_search_attributes && + ( + (exists($req->search_attributes->{page}) && defined($req->search_attributes->{page}) && length($req->search_attributes->{page})) + ||(exists($req->search_attributes->{offset}) && defined($req->search_attributes->{offset}) && length($req->search_attributes->{offset})) + ||(exists($req->search_attributes->{rows}) && defined($req->search_attributes->{rows}) && length($req->search_attributes->{rows})) + ); } catch { @@ -715,7 +720,7 @@ sub end :Private { $DB::single = 1; my $returned_objects = []; - map {my %inflated = $_->[0]->get_inflated_columns; push(@$returned_objects, \%inflated) } $c->req->all_objects; + push(@$returned_objects, $self->each_object_inflate($c, $_)) for map { $_->[0] } $c->req->all_objects; $c->stash->{response}->{$self->data_root} = scalar(@$returned_objects) > 1 ? $returned_objects : $returned_objects->[0]; } @@ -723,12 +728,24 @@ sub end :Private $c->forward('serialize'); } -# from Catalyst::Action::Serialize -sub serialize :ActionClass('Serialize') { - my ($self, $c) = @_; +=method_protected each_object_inflate + +each_object_inflate executes during L and allows hooking into the process of inflating the objects to return in the response. Receives, the context, and the object as arguments. + +This only executes if L if set and if there are any objects to actually return. + +=cut + +sub each_object_inflate +{ + my ($self, $c, $object) = @_; + return { $object->get_inflated_columns }; } +# from Catalyst::Action::Serialize +sub serialize :ActionClass('Serialize') { } + =method_protected push_error push_error stores an error message into the stash to be later retrieved by L. Accepts a Dict[message => Str] parameter that defines the error message.