@@ -, +, @@ my $c = shift->openapi->valid_input or return; my $args = $c->validation->output; my $vendors; return try { $vendors = Koha::Acquisition::Booksellers->api_list_search($c); return $c->render(status => 200, openapi => $vendors); } catch { ... } --- Koha/Objects.pm | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) --- a/Koha/Objects.pm +++ a/Koha/Objects.pm @@ -170,6 +170,48 @@ sub search_related { } } +=head3 search_for_api + + my @objects = Koha::Objects->earch_for_api( $c ); + +Searches for objects given a controller object I<$c>. + +=cut + +sub search_for_api { + my ( $self, $c ) = @_; + + my $args = $c->validation->output; + my $attributes; + + # Extract reserved params + my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($args); + + # Merge sorting into query attributes + $c->dbic_merge_sorting( + { + attributes => $attributes, + params => $reserved_params + } + ); + + # Merge pagination into query attributes + $c->dbic_merge_pagination( + { + attributes => $attributes, + params => $reserved_params + } + ); + + # Perform search + my $objects = $self->search( $filtered_params, $attributes ); + $c->add_pagination_headers({ total => $objects->count, params => $args }) + if $objects->is_paged; + + return $objects; +} + + =head3 single my $object = Koha::Objects->search({}, { rows => 1 })->single --