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/Stats.pm

23 lines
489 B
Perl
Raw Normal View History

2017-05-16 20:30:38 +00:00
package Pear::LocalLoop::Controller::Api::Stats;
use Mojo::Base 'Mojolicious::Controller';
sub post_today {
my $c = shift;
my $user = $c->stash->{api_user};
my $today_rs = $user->transactions->today_rs;
my $today_sum = $today_rs->get_column('value')->sum;
my $today_count = $today_rs->count;
return $c->render( json => {
success => Mojo::JSON->true,
today_sum => $today_sum,
today_count => $today_count,
today_avg => $today_sum / $today_count,
});
}
1;