Merge pull request #85 from Pear-Trading/finn/applegacy

added support for mobile app back
This commit is contained in:
Finn 2017-12-18 14:20:09 +00:00 committed by GitHub
commit 5ae8aa92f8
4 changed files with 60 additions and 4 deletions

View file

@ -6,7 +6,6 @@ requires 'Mojo::JSON';
requires 'Email::Valid';
requires 'Geo::UK::Postcode::Regex' => '0.017';
requires 'Authen::Passphrase::BlowfishCrypt';
requires 'Time::Fake';
requires 'Scalar::Util';
requires 'DBIx::Class';
requires 'DBIx::Class::PassphraseColumn';
@ -25,6 +24,11 @@ requires 'GIS::Distance';
requires 'Text::CSV';
requires 'Try::Tiny';
on 'test' => sub {
requires 'Test::More';
requires 'Test::MockTime';
};
feature 'schema-graph', 'Draw diagrams of Schema' => sub {
requires 'GraphViz';
requires 'SQL::Translator';
@ -38,4 +42,3 @@ feature 'postgres', 'PostgreSQL Support' => sub {
feature 'codepoint-open', 'Code Point Open manipulation' => sub {
requires 'Geo::UK::Postcode::CodePointOpen';
};

View file

@ -148,6 +148,7 @@ sub startup {
$api->post('/user/account')->to('api-user#post_account_update');
$api->post('/user-history')->to('api-user#post_user_history');
$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/paged')->to('api-stats#post_leaderboards_paged');
$api->post('/outgoing-transactions')->to('api-transactions#post_transaction_list_purchases');

View file

@ -15,6 +15,52 @@ has error_messages => sub {
sub post_index {
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 $duration = DateTime::Duration->new( weeks => 7 );

View file

@ -1,5 +1,9 @@
use Mojo::Base -strict;
BEGIN {
use Test::MockTime qw/ set_absolute_time /;
}
use FindBin qw/ $Bin /;
use Test::More;
@ -15,6 +19,8 @@ $framework->install_fixtures('users');
my $t = $framework->framework;
my $schema = $t->app->schema;
set_absolute_time('2017-01-01T00:00:00Z');
my $start = DateTime->today->subtract( hours => 12 );
# 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
$t->post_ok('/api/stats' => json => {
$t->post_ok('/api/stats/customer' => json => {
session_key => $session_key,
})
->status_is(200)->or($framework->dump_error)
->json_is('/weeks', {
purchases => [ 8, 21, 19, 22, 20, 20, 8 ],
purchases => [ 2, 21, 20, 21, 19, 22, 13 ],
})
->json_is('/sectors', {
sectors => ['A'],