Updated all endpoints to use new transaction value multiple

This commit is contained in:
Tom Bloor 2017-09-13 16:07:23 +01:00
parent c2cc0006bc
commit 1ffabb3e94
8 changed files with 33 additions and 23 deletions

View File

@ -18,23 +18,23 @@ sub post_index {
my $user = $c->stash->{api_user}->entity;
my $today_rs = $user->purchases->today_rs;
my $today_sum = $today_rs->get_column('value')->sum;
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;
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;
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;
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;
my $global_sum = $global_rs->get_column('value')->sum || 0;
my $global_count = $global_rs->count;
my $leaderboard_rs = $c->schema->resultset('Leaderboard');
@ -44,15 +44,15 @@ sub post_index {
return $c->render( json => {
success => Mojo::JSON->true,
today_sum => $today_sum || 0,
today_sum => $today_sum / 100000,
today_count => $today_count,
week_sum => $week_sum || 0,
week_sum => $week_sum / 100000,
week_count => $week_count,
month_sum => $month_sum || 0,
month_sum => $month_sum / 100000,
month_count => $month_count,
user_sum => $user_sum || 0,
user_sum => $user_sum / 100000,
user_count => $user_count,
global_sum => $global_sum || 0,
global_sum => $global_sum / 100000,
global_count => $global_count,
user_position => defined $current_user_position ? $current_user_position->position : 0,
});
@ -91,6 +91,10 @@ sub post_leaderboards {
my @leaderboard_array = $today_values->all;
if ( $validation->param('type') =~ /total$/ ) {
map { $_->{value} / 100000 } @leaderboard_array;
}
my $current_user_position = $today_values->find({ entity_id => $c->stash->{api_user}->entity->id });
return $c->render( json => {

View File

@ -34,7 +34,7 @@ sub post_transaction_list_purchases {
my @transaction_list = (
map {{
seller => $_->seller->name,
value => $_->value,
value => $_->value / 100000,
purchase_time => $_->purchase_time,
}} $transactions->all
);

View File

@ -176,7 +176,7 @@ sub post_upload {
'sales',
{
buyer => $user->entity,
value => $transaction_value,
value => $transaction_value * 100000,
( defined $file ? ( proof_image => $file ) : () ),
purchase_time => $c->format_db_datetime($purchase_time),
}

View File

@ -139,7 +139,7 @@ sub _sales_last_duration {
->get_column('value')
->sum || 0 + 0;
push @{ $data->{ labels } }, $start->day_name;
push @{ $data->{ data } }, $transactions;
push @{ $data->{ data } }, $transactions / 100000;
$start->add( days => 1 );
}
@ -171,7 +171,7 @@ sub _purchases_last_duration {
->get_column('value')
->sum || 0 + 0;
push @{ $data->{ labels } }, $start->day_name;
push @{ $data->{ data } }, $transactions;
push @{ $data->{ data } }, $transactions / 100000;
$start->add( days => 1 );
}

View File

@ -28,26 +28,32 @@ sub index {
my $today_sales = $entity->sales->search_between( $today, $now );
$data->{ today_sales_count } = $today_sales->count;
$data->{ today_sales_total } = $today_sales->get_column('value')->sum || 0;
$data->{ today_sales_total } /= 100000;
my $week_sales = $entity->sales->search_between( $week_ago, $today );
$data->{ this_week_sales_count } = $week_sales->count;
$data->{ this_week_sales_total } = $week_sales->get_column('value')->sum || 0;
$data->{ this_week_sales_total } /= 100000;
my $month_sales = $entity->sales->search_between( $month_ago, $today );
$data->{ this_month_sales_count } = $month_sales->count;
$data->{ this_month_sales_total } = $month_sales->get_column('value')->sum || 0;
$data->{ this_month_sales_total } /= 100000;
my $today_purchases = $entity->purchases->search_between( $today, $now );
$data->{ today_purchases_count } = $today_purchases->count;
$data->{ today_purchases_total } = $today_purchases->get_column('value')->sum || 0;
$data->{ today_purchases_total } /= 100000;
my $week_purchases = $entity->purchases->search_between( $week_ago, $today );
$data->{ this_week_purchases_count } = $week_purchases->count;
$data->{ this_week_purchases_total } = $week_purchases->get_column('value')->sum || 0;
$data->{ this_week_purchases_total } /= 100000;
my $month_purchases = $entity->purchases->search_between( $month_ago, $today );
$data->{ this_month_purchases_count } = $month_purchases->count;
$data->{ this_month_purchases_total } = $month_purchases->get_column('value')->sum || 0;
$data->{ this_month_purchases_total } /= 100000;
return $c->render(
json => {

View File

@ -43,7 +43,7 @@ $t->post_ok('/api/stats' => json => { session_key => $session_key } )
for ( 1 .. 10 ) {
$user_result->create_related( 'purchases', {
seller_id => $org_result->id,
value => $_,
value => $_ * 100000,
proof_image => 'a',
});
}
@ -51,7 +51,7 @@ for ( 1 .. 10 ) {
for ( 11 .. 20 ) {
$user_result->create_related( 'purchases', {
seller_id => $org_result->id,
value => $_,
value => $_ * 100000,
proof_image => 'a',
purchase_time => $dtf->format_datetime(DateTime->today()->subtract( days => 5 )),
});
@ -60,7 +60,7 @@ for ( 11 .. 20 ) {
for ( 21 .. 30 ) {
$user_result->create_related( 'purchases', {
seller_id => $org_result->id,
value => $_,
value => $_ * 100000,
proof_image => 'a',
purchase_time => $dtf->format_datetime(DateTime->today()->subtract( days => 25 )),
});
@ -69,7 +69,7 @@ for ( 21 .. 30 ) {
for ( 31 .. 40 ) {
$user_result->create_related( 'purchases', {
seller_id => $org_result->id,
value => $_,
value => $_ * 100000,
proof_image => 'a',
purchase_time => $dtf->format_datetime(DateTime->today()->subtract( days => 50 )),
});
@ -78,7 +78,7 @@ for ( 31 .. 40 ) {
for ( 41 .. 50 ) {
$org_result->create_related( 'purchases', {
seller_id => $org_result->id,
value => $_,
value => $_ * 100000,
proof_image => 'a',
purchase_time => $dtf->format_datetime(DateTime->today()->subtract( days => 50 )),
});
@ -91,8 +91,8 @@ is $user_result->purchases->search({
$dtf->format_datetime(DateTime->today()->add( days => 1 )),
],
},
})->get_column('value')->sum, 55, 'Got correct sum';
is $user_result->purchases->today_rs->get_column('value')->sum, 55, 'Got correct sum through rs';
})->get_column('value')->sum, 5500000, 'Got correct sum';
is $user_result->purchases->today_rs->get_column('value')->sum, 5500000, 'Got correct sum through rs';
$t->post_ok('/api/stats' => json => { session_key => $session_key } )
->status_is(200)

View File

@ -115,7 +115,7 @@ sub create_random_transaction {
$schema->resultset('Transaction')->create({
buyer => $buyer_result,
seller => $seller_result,
value => 10,
value => 10 * 100000,
proof_image => 'a',
purchase_time => $time,
});

View File

@ -73,7 +73,7 @@ sub create_random_transaction {
$schema->resultset('Transaction')->create({
buyer => $buyer_result,
seller => $seller_result,
value => 10,
value => 10 * 100000,
proof_image => 'a',
purchase_time => $time,
});