Bug 19410: Add Koha::Objects->search_for_api
authorTomas Cohen Arazi <tomascohen@theke.io>
Wed, 4 Oct 2017 18:41:35 +0000 (15:41 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 11 Dec 2017 20:46:59 +0000 (17:46 -0300)
commit7805ef2c01bf8a566daeb805b3c2f8943dafc80d
treeb7310c2ad6ee307fc48061ceaed74628b3f2bfa8
parent8430a541af9302ae6cef247253000c1469ae2f33
Bug 19410: Add Koha::Objects->search_for_api

Following the discussion about the best way to make things simpler for
developing the REST api, I quote Lari's email:

"As many other endpoint will have the exact same usage, by looking at your example, I would prefer to avoid writing parameter / pagination / sorting / header handling for each list operation in our API controllers. Do you think it's possible to centralize all of this e.g. by passing $c into a customized search sub? Perhaps in Koha::Objects?
so instead we could have something like (ignore my bad choice of naming)...:
sub list_vendors {
  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 {
    ...
  }
}"

We all agreed we neeed something like that. Here's a possible implementation. I take
advantage of the previously written Mojo helpers, that are fully covered by tests.

I submit this early so anyone can take a look and gather ideas to make it even better.
I'm already using it (effectively) for the /acquisitions/orders endpoint I'm writing
on bug 18731.

Thanks!

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Lari Taskula <lari.taskula@jns.fi>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/Objects.pm