Added outgoing transaction list API
This commit is contained in:
parent
bb239ba000
commit
06858fc005
3 changed files with 46 additions and 1 deletions
|
@ -154,6 +154,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('/outgoing-transactions')->to('api-transactions#post_transaction_list_purchases');
|
||||
|
||||
my $api_v1 = $api->under('/v1');
|
||||
|
||||
|
|
45
lib/Pear/LocalLoop/Controller/Api/Transactions.pm
Normal file
45
lib/Pear/LocalLoop/Controller/Api/Transactions.pm
Normal file
|
@ -0,0 +1,45 @@
|
|||
package Pear::LocalLoop::Controller::Api::Transactions;
|
||||
use Mojo::Base 'Mojolicious::Controller';
|
||||
use Mojo::JSON;
|
||||
|
||||
has error_messages => sub {
|
||||
return {
|
||||
email => {
|
||||
required => { message => 'No email sent.', status => 400 },
|
||||
email => { message => 'Email is invalid.', status => 400 },
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
sub post_transaction_list_purchases {
|
||||
my $c = shift;
|
||||
|
||||
my $user = $c->stash->{api_user};
|
||||
|
||||
my $validation = $c->validation;
|
||||
$validation->input( $c->stash->{api_json} );
|
||||
$validation->optional('page')->number;
|
||||
|
||||
return $c->api_validation_error if $validation->has_error;
|
||||
|
||||
my $transactions = $user->entity->purchases->search(
|
||||
undef, {
|
||||
page => $validation->param('page') || 1,
|
||||
rows => 10,
|
||||
order_by => { -desc => 'purchase_time' },
|
||||
},
|
||||
);
|
||||
my @transaction_list = (
|
||||
map {{
|
||||
seller => $_->entity->name,
|
||||
value => $_->value,
|
||||
purchase_time => $_->purchase_time,
|
||||
}} $transactions->all
|
||||
)
|
||||
return $c->render( json => {
|
||||
success => Mojo::JSON->true,
|
||||
transactions => \@transaction_list,
|
||||
});
|
||||
}
|
||||
|
||||
1;
|
|
@ -64,7 +64,6 @@ sub post_account {
|
|||
if ( defined $user_result ) {
|
||||
my $email = $user_result->email;
|
||||
|
||||
#Needs elsif added for trader page for this similar relevant entry
|
||||
if ( $user_result->type eq 'customer' ) {
|
||||
my $full_name = $user_result->entity->customer->full_name;
|
||||
my $display_name = $user_result->entity->customer->display_name;
|
||||
|
|
Reference in a new issue