Bug 19410 introduces a handy helper function to perform searches on Koha::Objects-based clases, plus several add-ons making use of other helpers. But it is still missing the ability to solve field mappings between the exposed API and the DB structure. We should add such a parameter.
Created attachment 69315 [details] [review] Bug 19686: Unit tests Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Created attachment 69316 [details] [review] Bug 19686: Add objects.search a 'to_model' param This patch introduces a new parameter to the objects.search Mojo helper. The idea behind this, is that if there's any attribute name mapping between the DB objects and the API exposed ones, we should be able to pass it to objects.search so the filtering query params are mapped correctly for building the DBIC query, like this example: my $patrons_set = Koha::Patrons->new; my @patrons = $c->objects->search( $patrons_set, \&to_model )->as_list; # and probably @patrons = map {to_api($_)} @patrons; The to_model function needs to avoid autovivification, to prevent messing with the query parameters (undef params). To test: - Apply this patches - Run: $ kshell k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t => SUCCESS: Tests pass! Params get mapped! - Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
fatal: sha1 information is lacking or useless (t/db_dependent/Koha/REST/Plugin/Objects.t).
David, please apply the dependencies in this specific order: - 19234 - 19369 - 19287 - 19370 - 19410 I've just tested it and it applies correctly.
So this fails for me. I get failed test messages that look like this: # Failed test 'exact match for JSON Pointer "/0/firstname"' # at t/db_dependent/Koha/REST/Plugin/Objects.t line 168. # got: 'Emmanuel' # expected: 'Manuel' But I also get this error at the beginning of the prove command: t/db_dependent/Koha/REST/Plugin/Objects.t .. DBD::mysql::st execute failed: Cannot delete or update a parent row: a foreign key constraint fails (`koha_master_dev_inlibro`.`issues`, CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON UPDATE CASCADE) [for Statement "DELETE FROM `borrowers`"] at /usr/local/share/perl/5.22.1/DBIx/Class/Storage/DBI.pm line 1836. No method delete found for Koha::Patrons DBIx::Class::Storage::DBI::_dbh_execute(): Cannot delete or update a parent row: a foreign key constraint fails (`koha_master_dev_inlibro`.`issues`, CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON UPDATE CASCADE) at /inlibro/git/koha-master-dev-inlibro/Koha/Objects.pm line 388 at t/db_dependent/Koha/REST/Plugin/Objects.t line 76. Is this a patch error or could it be a DB error?
Created attachment 69463 [details] [review] Bug 19686: Unit tests Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: David Bourgault <david.bourgault@inlibro.com>
Created attachment 69464 [details] [review] Bug 19686: Add objects.search a 'to_model' param This patch introduces a new parameter to the objects.search Mojo helper. The idea behind this, is that if there's any attribute name mapping between the DB objects and the API exposed ones, we should be able to pass it to objects.search so the filtering query params are mapped correctly for building the DBIC query, like this example: my $patrons_set = Koha::Patrons->new; my @patrons = $c->objects->search( $patrons_set, \&to_model )->as_list; # and probably @patrons = map {to_api($_)} @patrons; The to_model function needs to avoid autovivification, to prevent messing with the query parameters (undef params). To test: - Apply this patches - Run: $ kshell k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t => SUCCESS: Tests pass! Params get mapped! - Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: David Bourgault <david.bourgault@inlibro.com>
My bad. I tested again with a fresh BD and it worked. Test passed, QA tool green.
Created attachment 70626 [details] [review] Bug 19686: (followup) Add to_api param for completeness This patch adds (yet) another param to objects.search: a reference to a to_api function to be applied when processing the search results for output. To test: - Apply this patch - Run: $ kshell k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t => SUCCESS: Test count raised, and tests pass! - Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Created attachment 71742 [details] [review] Bug 19686: Unit tests Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: David Bourgault <david.bourgault@inlibro.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Created attachment 71743 [details] [review] Bug 19686: Add objects.search a 'to_model' param This patch introduces a new parameter to the objects.search Mojo helper. The idea behind this, is that if there's any attribute name mapping between the DB objects and the API exposed ones, we should be able to pass it to objects.search so the filtering query params are mapped correctly for building the DBIC query, like this example: my $patrons_set = Koha::Patrons->new; my @patrons = $c->objects->search( $patrons_set, \&to_model )->as_list; # and probably @patrons = map {to_api($_)} @patrons; The to_model function needs to avoid autovivification, to prevent messing with the query parameters (undef params). To test: - Apply this patches - Run: $ kshell k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t => SUCCESS: Tests pass! Params get mapped! - Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: David Bourgault <david.bourgault@inlibro.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Created attachment 71744 [details] [review] Bug 19686: (followup) Add to_api param for completeness This patch adds (yet) another param to objects.search: a reference to a to_api function to be applied when processing the search results for output. To test: - Apply this patch - Run: $ kshell k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t => SUCCESS: Test count raised, and tests pass! - Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Pushed to master for 18.05, thanks to everybody involved!