added snippet endpoint and test
This commit is contained in:
parent
b3f1a018b5
commit
3100fec233
4 changed files with 115 additions and 8 deletions
|
@ -16,13 +16,14 @@ sub index {
|
|||
my $validation = $c->validation;
|
||||
$validation->input( $c->stash->{api_json} );
|
||||
$validation->required('graph')->in( qw/
|
||||
customers_last_7_days
|
||||
customers_last_30_days
|
||||
sales_last_7_days
|
||||
sales_last_30_days
|
||||
purchases_last_7_days
|
||||
purchases_last_30_days
|
||||
customers_range
|
||||
total_today
|
||||
avg_spend_today
|
||||
total_last_week
|
||||
avg_spend_last_week
|
||||
total_last_month
|
||||
avg_spend_last_month
|
||||
total_user
|
||||
avg_spend_user
|
||||
/ );
|
||||
|
||||
return $c->api_validation_error if $validation->has_error;
|
||||
|
|
31
lib/Pear/LocalLoop/Controller/Api/V1/Customer/Snippets.pm
Normal file
31
lib/Pear/LocalLoop/Controller/Api/V1/Customer/Snippets.pm
Normal file
|
@ -0,0 +1,31 @@
|
|||
package Pear::LocalLoop::Controller::Api::V1::Customer::Snippets;
|
||||
use Mojo::Base 'Mojolicious::Controller';
|
||||
|
||||
sub index {
|
||||
my $c = shift;
|
||||
|
||||
my $entity = $c->stash->{api_user}->entity;
|
||||
my $data = {
|
||||
user_sum => 0,
|
||||
user_position => 0,
|
||||
};
|
||||
|
||||
my $user_rs = $entity->purchases;
|
||||
$data->{ user_sum } = $user_rs->get_column('value')->sum || 0;
|
||||
$data->{ user_sum } /= 100000;
|
||||
|
||||
my $leaderboard_rs = $c->schema->resultset('Leaderboard');
|
||||
my $monthly_board = $leaderboard_rs->get_latest( 'monthly_total' );
|
||||
my $monthly_values = $monthly_board->values;
|
||||
$data->{ user_position } = $monthly_values ? $monthly_values->find({ entity_id => $entity->id })->position : 0;
|
||||
|
||||
return $c->render(
|
||||
json => {
|
||||
success => Mojo::JSON->true,
|
||||
snippets => $data,
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
1;
|
Reference in a new issue