This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
Foodloop-Server/lib/Pear/LocalLoop/Controller/Api/V1/Customer/Snippets.pm

36 lines
928 B
Perl
Raw Normal View History

2017-12-12 17:21:32 +00:00
package Pear::LocalLoop::Controller::Api::V1::Customer::Snippets;
use Mojo::Base 'Mojolicious::Controller';
sub index {
2021-03-20 12:09:50 +00:00
my $c = shift;
2017-12-12 17:21:32 +00:00
2021-03-20 12:09:50 +00:00
my $entity = $c->stash->{api_user}->entity;
my $data = {
user_sum => 0,
user_position => 0,
};
2017-12-12 17:21:32 +00:00
2021-03-20 12:09:50 +00:00
my $user_rs = $entity->purchases;
$data->{user_sum} = $user_rs->get_column('value')->sum || 0;
$data->{user_sum} /= 100000;
2017-12-12 17:21:32 +00:00
2021-03-20 12:09:50 +00:00
my $leaderboard_rs = $c->schema->resultset('Leaderboard');
my $monthly_board = $leaderboard_rs->get_latest('monthly_total');
if ( defined $monthly_board ) {
my $monthly_values = $monthly_board->values;
$data->{user_position} =
$monthly_values
? $monthly_values->find( { entity_id => $entity->id } )->position
: 0;
2017-12-12 17:21:32 +00:00
}
2021-03-20 12:09:50 +00:00
return $c->render(
json => {
success => Mojo::JSON->true,
snippets => $data,
}
);
2017-12-12 17:21:32 +00:00
}
1;