From 85c80980c3a9a6fcfd53639adda0b97df00060bf Mon Sep 17 00:00:00 2001 From: Finn Date: Mon, 14 Aug 2017 11:15:33 +0100 Subject: [PATCH] Added code for date submission in receipt upload --- lib/Pear/LocalLoop/Controller/Api/Upload.pm | 16 ++++++++++++++-- lib/Pear/LocalLoop/Schema/Result/Transaction.pm | 5 +++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Api/Upload.pm b/lib/Pear/LocalLoop/Controller/Api/Upload.pm index 7953b7f..6db9dc1 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Upload.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Upload.pm @@ -19,6 +19,10 @@ The value of the transaction Is a value of 1, 2, or 3 - depending on the type of transaction. +=item * purchase_time + +Is a DateTime value submitted for when the receipt is from. + =item * organisation_id An ID of a valid organisation. used when transaction_type is 1 or 2. @@ -54,6 +58,9 @@ has error_messages => sub { number => { message => 'transaction_value does not look like a number', status => 400 }, gt_num => { message => 'transaction_value cannot be equal to or less than zero', status => 400 }, }, + purchase_time => { + required => { message => 'purchase_time is missing', status => 400 }, + }, file => { required => { message => 'No file uploaded', status => 400 }, upload => { message => 'file key does not contain a file', status => 400 }, @@ -92,6 +99,9 @@ sub post_upload { $validation->required('transaction_value')->number->gt_num(0); $validation->required('transaction_type')->in( 1, 2, 3 ); + #Check a purchase time was submitted + $validation->required('purchase_time'); + # First pass of required items return $c->api_validation_error if $validation->has_error; @@ -112,7 +122,7 @@ sub post_upload { # Unvalidated Organisation my $valid_org_rs = $c->schema->resultset('PendingOrganisation')->search({ submitted_by_id => $user->id }); $validation->required('organisation_id')->number->in_resultset( 'id', $valid_org_rs ); - + return $c->api_validation_error if $validation->has_error; $organisation = $valid_org_rs->find( $validation->param('organisation_id') ); @@ -123,7 +133,7 @@ sub post_upload { $validation->optional('street_name'); $validation->optional('town'); $validation->optional('postcode')->postcode; - + return $c->api_validation_error if $validation->has_error; $organisation = $c->schema->resultset('PendingOrganisation')->create({ @@ -138,6 +148,7 @@ sub post_upload { my $transaction_value = $validation->param('transaction_value'); my $upload = $validation->param('file'); + my $purchase_time = $validation->param('purchase_time'); my $file = $c->store_file_from_upload( $upload ); $organisation->create_related( @@ -146,6 +157,7 @@ sub post_upload { buyer => $user, value => $transaction_value, proof_image => $file, + purchase_time => $purchase_time, } ); diff --git a/lib/Pear/LocalLoop/Schema/Result/Transaction.pm b/lib/Pear/LocalLoop/Schema/Result/Transaction.pm index 198c9ee..366e40f 100644 --- a/lib/Pear/LocalLoop/Schema/Result/Transaction.pm +++ b/lib/Pear/LocalLoop/Schema/Result/Transaction.pm @@ -42,6 +42,11 @@ __PACKAGE__->add_columns( is_nullable => 0, set_on_create => 1, }, + "purchase_time" => { + data_type => "datetime", + is_nullable => 0, + set_on_create => 1, + }, ); __PACKAGE__->set_primary_key("id");