Add API endpoint for sending push notis
This commit is contained in:
parent
de3def3b5e
commit
0eabd9cf1e
2 changed files with 44 additions and 0 deletions
|
@ -141,6 +141,8 @@ sub startup {
|
||||||
$api_public->post('/register')->to('api-register#post_register');
|
$api_public->post('/register')->to('api-register#post_register');
|
||||||
$api_public->post('/logout')->to('api-auth#post_logout');
|
$api_public->post('/logout')->to('api-auth#post_logout');
|
||||||
$api_public->post('/feedback')->to('api-feedback#post_feedback');
|
$api_public->post('/feedback')->to('api-feedback#post_feedback');
|
||||||
|
$api_public->post('/send-message')->to('api-sendmessage#post_message');
|
||||||
|
#$api_public->post('/send-message')->to('api-sendmessage#post_message');
|
||||||
|
|
||||||
# Private, must be authenticated api routes
|
# Private, must be authenticated api routes
|
||||||
my $api = $api_public->under('/')->to('api-auth#auth');
|
my $api = $api_public->under('/')->to('api-auth#auth');
|
||||||
|
|
42
lib/Pear/LocalLoop/Controller/Api/Sendmessage.pm
Normal file
42
lib/Pear/LocalLoop/Controller/Api/Sendmessage.pm
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
package Pear::LocalLoop::Controller::Api::Sendmessage;
|
||||||
|
use Mojo::Base 'Mojolicious::Controller';
|
||||||
|
|
||||||
|
has error_messages => sub {
|
||||||
|
return {
|
||||||
|
email => {
|
||||||
|
required => { message => 'Email is required or not registered', status => 400 },
|
||||||
|
in_resultset => { message => 'Email is required or not registered', status => 400, error => "required" },
|
||||||
|
},
|
||||||
|
messagetext => {
|
||||||
|
required => { message => 'Message is required', status => 400 },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
sub post_message {
|
||||||
|
my $c = shift;
|
||||||
|
|
||||||
|
my $validation = $c->validation;
|
||||||
|
$validation->input( $c->stash->{api_json} );
|
||||||
|
|
||||||
|
my $user_rs = $c->schema->resultset('User');
|
||||||
|
|
||||||
|
# $validation->required('email')->in_resultset( 'email', $user_rs );
|
||||||
|
$validation->required('messagetext');
|
||||||
|
|
||||||
|
return $c->api_validation_error if $validation->has_error;
|
||||||
|
|
||||||
|
my $user = $user_rs->find({'email' => $validation->param('email')});
|
||||||
|
=begin comment
|
||||||
|
$c->schema->resultset('Feedback')->create({
|
||||||
|
user => $user,
|
||||||
|
messagetext => $validation->param('messagetext'),
|
||||||
|
});
|
||||||
|
=cut
|
||||||
|
return $c->render( json => {
|
||||||
|
success => Mojo::JSON->true,
|
||||||
|
message => 'Your message has been sent successfully!',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
Reference in a new issue