This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
Foodloop-Server/lib/Pear/LocalLoop/Controller/Api/Transactions.pm

50 lines
1.2 KiB
Perl
Raw Normal View History

2017-09-05 15:37:31 +00:00
package Pear::LocalLoop::Controller::Api::Transactions;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::JSON;
has error_messages => sub {
return {
email => {
required => { message => 'No email sent.', status => 400 },
email => { message => 'Email is invalid.', status => 400 },
},
};
};
sub post_transaction_list_purchases {
my $c = shift;
my $user = $c->stash->{api_user};
my $validation = $c->validation;
$validation->input( $c->stash->{api_json} );
$validation->optional('page')->number;
return $c->api_validation_error if $validation->has_error;
my $transactions = $user->entity->purchases->search(
undef, {
page => $validation->param('page') || 1,
rows => 10,
order_by => { -desc => 'purchase_time' },
},
);
# purchase_time needs timezone attached to it
2017-09-05 15:37:31 +00:00
my @transaction_list = (
map {{
seller => $_->seller->name,
value => $_->value / 100000,
2017-09-19 16:40:17 +00:00
purchase_time => $c->format_iso_datetime($_->purchase_time),
2017-09-05 15:37:31 +00:00
}} $transactions->all
);
2017-09-05 15:37:31 +00:00
return $c->render( json => {
success => Mojo::JSON->true,
transactions => \@transaction_list,
2017-09-06 16:03:53 +00:00
page_no => $transactions->pager->total_entries,
2017-09-05 15:37:31 +00:00
});
}
1;