added support for mobile app back

This commit is contained in:
Finn 2017-12-18 12:56:45 +00:00
parent 8ed5e5d9ff
commit e6ce9cc81a
3 changed files with 48 additions and 1 deletions

View file

@ -148,6 +148,7 @@ sub startup {
$api->post('/user/account')->to('api-user#post_account_update'); $api->post('/user/account')->to('api-user#post_account_update');
$api->post('/user-history')->to('api-user#post_user_history'); $api->post('/user-history')->to('api-user#post_user_history');
$api->post('/stats')->to('api-stats#post_index'); $api->post('/stats')->to('api-stats#post_index');
$api->post('/stats/customer')->to('api-stats#post_customer');
$api->post('/stats/leaderboard')->to('api-stats#post_leaderboards'); $api->post('/stats/leaderboard')->to('api-stats#post_leaderboards');
$api->post('/stats/leaderboard/paged')->to('api-stats#post_leaderboards_paged'); $api->post('/stats/leaderboard/paged')->to('api-stats#post_leaderboards_paged');
$api->post('/outgoing-transactions')->to('api-transactions#post_transaction_list_purchases'); $api->post('/outgoing-transactions')->to('api-transactions#post_transaction_list_purchases');

View file

@ -15,6 +15,52 @@ has error_messages => sub {
sub post_index { sub post_index {
my $c = shift; my $c = shift;
my $user = $c->stash->{api_user}->entity;
my $today_rs = $user->purchases->today_rs;
my $today_sum = $today_rs->get_column('value')->sum || 0;
my $today_count = $today_rs->count;
my $week_rs = $user->purchases->week_rs;
my $week_sum = $week_rs->get_column('value')->sum || 0;
my $week_count = $week_rs->count;
my $month_rs = $user->purchases->month_rs;
my $month_sum = $month_rs->get_column('value')->sum || 0;
my $month_count = $month_rs->count;
my $user_rs = $user->purchases;
my $user_sum = $user_rs->get_column('value')->sum || 0;
my $user_count = $user_rs->count;
my $global_rs = $c->schema->resultset('Transaction');
my $global_sum = $global_rs->get_column('value')->sum || 0;
my $global_count = $global_rs->count;
my $leaderboard_rs = $c->schema->resultset('Leaderboard');
my $monthly_board = $leaderboard_rs->get_latest( 'monthly_total' );
my $monthly_values = $monthly_board->values;
my $current_user_position = $monthly_values ? $monthly_values->find({ entity_id => $user->id }) : undef;
return $c->render( json => {
success => Mojo::JSON->true,
today_sum => $today_sum / 100000,
today_count => $today_count,
week_sum => $week_sum / 100000,
week_count => $week_count,
month_sum => $month_sum / 100000,
month_count => $month_count,
user_sum => $user_sum / 100000,
user_count => $user_count,
global_sum => $global_sum / 100000,
global_count => $global_count,
user_position => defined $current_user_position ? $current_user_position->position : 0,
});
}
sub post_customer {
my $c = shift;
my $entity = $c->stash->{api_user}->entity; my $entity = $c->stash->{api_user}->entity;
my $duration = DateTime::Duration->new( weeks => 7 ); my $duration = DateTime::Duration->new( weeks => 7 );

View file

@ -40,7 +40,7 @@ my $session_key = $framework->login({
#TODO be able to define start and end below in request #TODO be able to define start and end below in request
$t->post_ok('/api/stats' => json => { $t->post_ok('/api/stats/customer' => json => {
session_key => $session_key, session_key => $session_key,
}) })
->status_is(200)->or($framework->dump_error) ->status_is(200)->or($framework->dump_error)