Bug 19410 - Koha::Objects needs a ->search_for_api method
Summary: Koha::Objects needs a ->search_for_api method
Status: Needs Signoff
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Tomás Cohen Arazi
QA Contact: Testopia
URL:
Whiteboard:
Keywords:
Depends on: 19196 19234 19278 19369 19370
Blocks: 18731
  Show dependency treegraph
 
Reported: 2017-10-04 18:49 UTC by Tomás Cohen Arazi
Modified: 2017-10-19 14:38 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Bot Control: ---
When did the bot last check this:
Who signed the patch off:
Text to go in the release notes:


Attachments
Bug 19410: Add Koha::Objects->search_for_api (2.71 KB, patch)
2017-10-04 18:59 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 19410: Add Koha::Objects->search_for_api (3.90 KB, patch)
2017-10-06 15:55 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 19410: Unit tests (2.93 KB, patch)
2017-10-06 15:55 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 19410: Add Koha::Objects->search_for_api (4.14 KB, patch)
2017-10-06 17:27 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 19410: Unit tests (2.92 KB, patch)
2017-10-06 17:27 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 19410: (follow-up) Fix typo in POD (650 bytes, patch)
2017-10-07 12:56 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 19410: (follow-up) Fix typo in POD (650 bytes, patch)
2017-10-07 13:06 UTC, Lari Taskula
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Tomás Cohen Arazi 2017-10-04 18:49:13 UTC
We should extend Koha::Objects so searching can deal with squery parameters, specially handling pagination, results sorting, matching criteria, etc.

This could be easily implemented using:

- Bug 19196 (Pagination handling helpers)
- Bug 19278 (Make REST api default page size configurable)
- Bug 19234 (Query params handling helpers)
- Bug 19369 (Query pagination to SQL::Abstract)
- Bug 19370 (Query order by to SQL::Abstract)
Comment 1 Tomás Cohen Arazi 2017-10-04 18:59:13 UTC Comment hidden (obsolete)
Comment 2 Tomás Cohen Arazi 2017-10-06 15:55:49 UTC Comment hidden (obsolete)
Comment 3 Tomás Cohen Arazi 2017-10-06 15:55:54 UTC Comment hidden (obsolete)
Comment 4 Tomás Cohen Arazi 2017-10-06 17:27:49 UTC
Created attachment 67750 [details] [review]
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!
Comment 5 Tomás Cohen Arazi 2017-10-06 17:27:55 UTC
Created attachment 67751 [details] [review]
Bug 19410: Unit tests
Comment 6 Lari Taskula 2017-10-07 12:56:55 UTC
Created attachment 67795 [details] [review]
Bug 19410: (follow-up) Fix typo in POD
Comment 7 Lari Taskula 2017-10-07 13:06:57 UTC
Created attachment 67798 [details] [review]
Bug 19410: (follow-up) Fix typo in POD