Merge branch 'development' into TBSliver/Admin-Improvements

Conflicts:
	CHANGELOG.md
This commit is contained in:
Tom Bloor 2017-11-14 12:43:29 +00:00
commit cb7ab797f5
3 changed files with 70 additions and 0 deletions

View file

@ -7,6 +7,10 @@
* **Admin Feature** Added `is_local` flag to Organisations to start categorising odd stores
* **Admin Feature** Feedback items now word wrap
* **Admin Feature** Rework transaction viewing
# v0.9.5
* Added leaderboard api for web-app with pagination
* Location is now updated on registration. Customers location is truncated to 2
decimal places based on their postcode.
* Location is also updated on changing a users postcode

View file

@ -148,6 +148,7 @@ sub startup {
$api->post('/user-history')->to('api-user#post_user_history');
$api->post('/stats')->to('api-stats#post_index');
$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

@ -109,4 +109,69 @@ sub post_leaderboards {
});
}
sub post_leaderboards_paged {
my $c = shift;
my $validation = $c->validation;
$validation->input( $c->stash->{api_json} );
my $leaderboard_rs = $c->schema->resultset('Leaderboard');
$validation->required('type')->in_resultset( 'type', $leaderboard_rs );
$validation->optional('page')->number;
return $c->api_validation_error if $validation->has_error;
my $page = 1;
my $today_board = $leaderboard_rs->get_latest( $validation->param('type') );
if ( !defined $validation->param('page') || $validation->param('page') < 1 ) {
my $user_position = $today_board->values->find({ entity_id => $c->stash->{api_user}->entity->id });
$page = int(defined $user_position ? $user_position->{position} : 0 / 10) + 1;
} else {
$page = $validation->param('page');
}
my $today_values = $today_board->values->search(
{},
{
page => $page,
rows => 10,
order_by => { -asc => 'me.position' },
columns => [
qw/
me.value
me.trend
me.position
/,
{ display_name => 'customer.display_name' },
],
join => { entity => 'customer' },
},
);
$today_values->result_class( 'DBIx::Class::ResultClass::HashRefInflator' );
my @leaderboard_array = $today_values->all;
if ( $validation->param('type') =~ /total$/ ) {
@leaderboard_array = (map {
{
%$_,
value => $_->{value} / 100000,
}
} @leaderboard_array);
}
my $current_user_position = $today_values->find({ entity_id => $c->stash->{api_user}->entity->id });
return $c->render( json => {
success => Mojo::JSON->true,
leaderboard => [ @leaderboard_array ],
user_position => defined $current_user_position ? $current_user_position->{position} : 0,
page => $page,
count => $today_values->pager->total_entries,
});
}
1;