{
$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
If the L</select> config param is defined then the hashes will contain only those columns, otherwise all columns in the object will be returned. L</select> of course supports the function/procedure calling semantics that L<DBIx::Class::ResultSet/select>. In order to have proper column names in the result, provide arguments in L</as> (which also follows L<DBIx::Class::ResultSet/as> semantics. Similarly L</count>, L</page>, L</grouped_by> and L</ordered_by> affect the maximum number of rows returned as well as the ordering and grouping. Note that if select, count, ordered_by or grouped_by request parameters are present then these will override the values set on the class with select becoming bound by the select_exposes attribute.
-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 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 used as the search condition.
For example, these request parameters:
$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}));
}
catch
{
{
$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];
}
$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</end> 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</return_object> 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</end>. Accepts a Dict[message => Str] parameter that defines the error message.
BEGIN { extends 'MyApp::ControllerBase::DBIC::API::RPC' };
...
-It should be noted that the L</return_object> attribute will produce the above result for you, free of charge.
+It should be noted that the return_object attribute will produce the above result for you, free of charge.
For REST the only difference besides the class names would be that create should be :Private rather than an endpoint.