Merge pull request #85 from Pear-Trading/finn/applegacy
added support for mobile app back
This commit is contained in:
commit
4653f713fa
4 changed files with 60 additions and 4 deletions
7
cpanfile
7
cpanfile
|
@ -6,7 +6,6 @@ requires 'Mojo::JSON';
|
||||||
requires 'Email::Valid';
|
requires 'Email::Valid';
|
||||||
requires 'Geo::UK::Postcode::Regex' => '0.017';
|
requires 'Geo::UK::Postcode::Regex' => '0.017';
|
||||||
requires 'Authen::Passphrase::BlowfishCrypt';
|
requires 'Authen::Passphrase::BlowfishCrypt';
|
||||||
requires 'Time::Fake';
|
|
||||||
requires 'Scalar::Util';
|
requires 'Scalar::Util';
|
||||||
requires 'DBIx::Class';
|
requires 'DBIx::Class';
|
||||||
requires 'DBIx::Class::PassphraseColumn';
|
requires 'DBIx::Class::PassphraseColumn';
|
||||||
|
@ -25,6 +24,11 @@ requires 'GIS::Distance';
|
||||||
requires 'Text::CSV';
|
requires 'Text::CSV';
|
||||||
requires 'Try::Tiny';
|
requires 'Try::Tiny';
|
||||||
|
|
||||||
|
on 'test' => sub {
|
||||||
|
requires 'Test::More';
|
||||||
|
requires 'Test::MockTime';
|
||||||
|
};
|
||||||
|
|
||||||
feature 'schema-graph', 'Draw diagrams of Schema' => sub {
|
feature 'schema-graph', 'Draw diagrams of Schema' => sub {
|
||||||
requires 'GraphViz';
|
requires 'GraphViz';
|
||||||
requires 'SQL::Translator';
|
requires 'SQL::Translator';
|
||||||
|
@ -38,4 +42,3 @@ feature 'postgres', 'PostgreSQL Support' => sub {
|
||||||
feature 'codepoint-open', 'Code Point Open manipulation' => sub {
|
feature 'codepoint-open', 'Code Point Open manipulation' => sub {
|
||||||
requires 'Geo::UK::Postcode::CodePointOpen';
|
requires 'Geo::UK::Postcode::CodePointOpen';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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');
|
||||||
|
|
|
@ -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 );
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
use Mojo::Base -strict;
|
use Mojo::Base -strict;
|
||||||
|
|
||||||
|
BEGIN {
|
||||||
|
use Test::MockTime qw/ set_absolute_time /;
|
||||||
|
}
|
||||||
|
|
||||||
use FindBin qw/ $Bin /;
|
use FindBin qw/ $Bin /;
|
||||||
|
|
||||||
use Test::More;
|
use Test::More;
|
||||||
|
@ -15,6 +19,8 @@ $framework->install_fixtures('users');
|
||||||
my $t = $framework->framework;
|
my $t = $framework->framework;
|
||||||
my $schema = $t->app->schema;
|
my $schema = $t->app->schema;
|
||||||
|
|
||||||
|
set_absolute_time('2017-01-01T00:00:00Z');
|
||||||
|
|
||||||
my $start = DateTime->today->subtract( hours => 12 );
|
my $start = DateTime->today->subtract( hours => 12 );
|
||||||
|
|
||||||
# create 40 days worth of data
|
# create 40 days worth of data
|
||||||
|
@ -40,12 +46,12 @@ 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)
|
||||||
->json_is('/weeks', {
|
->json_is('/weeks', {
|
||||||
purchases => [ 8, 21, 19, 22, 20, 20, 8 ],
|
purchases => [ 2, 21, 20, 21, 19, 22, 13 ],
|
||||||
})
|
})
|
||||||
->json_is('/sectors', {
|
->json_is('/sectors', {
|
||||||
sectors => ['A'],
|
sectors => ['A'],
|
||||||
|
|
Reference in a new issue