From b1ab789455f271461d7092e9ceaf448af0c9a0a5 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Mon, 15 Jul 2019 10:11:59 +0100 Subject: [PATCH] Added search ref option --- lib/Pear/LocalLoop/Controller/Api/External.pm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Api/External.pm b/lib/Pear/LocalLoop/Controller/Api/External.pm index 79d9df4..1b94d5b 100644 --- a/lib/Pear/LocalLoop/Controller/Api/External.pm +++ b/lib/Pear/LocalLoop/Controller/Api/External.pm @@ -13,19 +13,23 @@ sub post_lcc_transactions { $validation->input($c->stash->{api_json}); $validation->optional('page')->number; $validation->optional('per_page')->number; + $validation->optional('search'); return $c->api_validation_error if $validation->has_error; - my $lcc_import_ext_ref = $c->schema->resultset('ExternalReference')->find({ name => 'LCC CSV' }); - - return 0 unless $lcc_import_ext_ref; + my $search_ref = undef; + if ( $validation->param('search') ) { + $search_ref = { + "organisation.name" => { '-like' => join( '', '%', $validation->param('search'), '%' ) }, + }; + } my $lcc_transactions = $lcc_import_ext_ref->transactions->search( - undef, + $search_ref, { page => $validation->param('page') || 1, rows => $validation->param('per_page') || 10, - join => 'transaction', + join => [ 'transaction', 'organisation' ], order_by => { -desc => 'transaction.purchase_time' }, });