From 37ffd53054dc649a576e8056160a855c4f22f040 Mon Sep 17 00:00:00 2001 From: Finn Date: Tue, 13 Mar 2018 12:55:13 +0000 Subject: [PATCH] amended upload to allow for validation changes --- .../LocalLoop/Controller/Api/Transactions.pm | 19 ++++++++++++++++++- lib/Pear/LocalLoop/Controller/Api/Upload.pm | 6 +++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Api/Transactions.pm b/lib/Pear/LocalLoop/Controller/Api/Transactions.pm index 4a0ae8c..9273c2d 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Transactions.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Transactions.pm @@ -30,7 +30,11 @@ sub post_transaction_list_purchases { }, ); -# purchase_time needs timezone attached to it + my $recurring_transactions = $c->schema->resultset('TransactionRecurring')->search({ + buyer_id => $user->id, + }); + + # purchase_time needs timezone attached to it my @transaction_list = ( map {{ seller => $_->seller->name, @@ -39,9 +43,22 @@ sub post_transaction_list_purchases { }} $transactions->all ); + my @recurring_transaction_list = ( + map {{ + seller => $_->seller->name, + value => $_->value / 100000, + start_time => $c->format_iso_datetime($_->start_time), + last_updated => $c->format_iso_datetime($_->last_updated), + essential => $_->essential, + category => $_->category->category->name, + recurring_period => $_->recurring_period, + }} $recurring_transactions->all + ); + return $c->render( json => { success => Mojo::JSON->true, transactions => \@transaction_list, + recurring_transactions => \@recurring_transaction_list, page_no => $transactions->pager->total_entries, }); } diff --git a/lib/Pear/LocalLoop/Controller/Api/Upload.pm b/lib/Pear/LocalLoop/Controller/Api/Upload.pm index dea5678..61f1d2b 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Upload.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Upload.pm @@ -147,7 +147,7 @@ sub post_upload { # Unknown Organisation $validation->required('organisation_name'); $validation->optional('street_name'); - $validation->required('town'); + $validation->optional('town'); $validation->optional('postcode')->postcode; return $c->api_validation_error if $validation->has_error; @@ -198,7 +198,7 @@ sub post_upload { ( defined $file ? ( proof_image => $file ) : () ), purchase_time => $c->format_db_datetime($purchase_time), essential => ( defined $essential ? $essential : 0 ), - distance => $distance, + distance => ( defined $category ? $category : undef ), } ); @@ -227,7 +227,7 @@ sub post_upload { value => $transaction_value * 100000, start_time => $c->format_db_datetime($purchase_time), essential => ( defined $essential ? $essential : 0 ), - distance => $distance, + distance => ( defined $category ? $category : undef ), category_id => ( defined $category ? $category : undef ), recurring_period => $recurring_period, });