Added API endpoints and user info retrieval

This commit is contained in:
Finn 2017-07-26 18:28:14 +01:00
parent b0e9ef249a
commit 2b3c13518b
2 changed files with 47 additions and 0 deletions

View file

@ -147,6 +147,8 @@ sub startup {
}); });
$api->post('/upload')->to('api-upload#post_upload'); $api->post('/upload')->to('api-upload#post_upload');
$api->post('/search')->to('api-upload#post_search'); $api->post('/search')->to('api-upload#post_search');
$api->post('/user')->to('api-user#post_account');
$api->post('/user/account')->to('api-user#post_account_update');
$api->post('/user/day')->to('api-user#post_day'); $api->post('/user/day')->to('api-user#post_day');
$api->post('/edit')->to('api-api#post_edit'); $api->post('/edit')->to('api-api#post_edit');
$api->post('/fetchuser')->to('api-api#post_fetchuser'); $api->post('/fetchuser')->to('api-api#post_fetchuser');

View file

@ -26,4 +26,49 @@ sub post_day {
}); });
} }
sub post_account {
my $c = shift;
my $user = $c->stash->{api_user};
my $user_result = $c->schema->resultset('User')->find({ user_id => $c->stash->{api_user}->id });
if ( defined $user_result ) {
my $email = $user_result->email;
my $full_name;
my $display_name;
my $postcode;
#Needs elsif added for trader page for this similar relevant entry
if ( defined $user_result->customer_id ) {
$full_name = $user_result->customer->full_name;
$display_name = $user_result->customer->display_name;
$postcode = $user_result->customer->postcode;
} elsif ( defined $user_result->organisation_id ) {
$display_name = $user_result->organisation->name;
} else {
return undef;
}
return $c->render( json => {
success => Mojo::JSON->true,
session_key => $session_key,
full_name => $full_name,
display_name => $display_name,
email => $email,
postcode => $postcode,
});
}
return $c->render(
json => {
success => Mojo::JSON->false,
message => 'Email or password is invalid.',
},
status => 401
);
}
sub post_account_update {
}
1; 1;