diff --git a/lib/Pear/LocalLoop.pm b/lib/Pear/LocalLoop.pm index 5409d4e..c05fafb 100644 --- a/lib/Pear/LocalLoop.pm +++ b/lib/Pear/LocalLoop.pm @@ -132,6 +132,7 @@ sub startup { $api_public->post('/login')->to('api-auth#post_login'); $api_public->post('/register')->to('api-register#post_register'); $api_public->post('/logout')->to('api-auth#post_logout'); + $api_public->post('/feedback')->to('api-feedback#post_feedback'); # Private, must be authenticated api routes my $api = $api_public->under('/')->to('api-auth#auth'); diff --git a/lib/Pear/LocalLoop/Controller/Api/Feedback.pm b/lib/Pear/LocalLoop/Controller/Api/Feedback.pm new file mode 100644 index 0000000..8895ace --- /dev/null +++ b/lib/Pear/LocalLoop/Controller/Api/Feedback.pm @@ -0,0 +1,47 @@ +package Pear::LocalLoop::Controller::Api::Feedback; +use Mojo::Base 'Mojolicious::Controller'; + +has error_messages => sub { + return { + email => { + required => { message => 'Email is required', status => 400 }, + in_resultset => { message => 'Change meeee', status => 400 }, + }, + app_name => { + required => { message => 'App Name is required', status => 400 }, + }, + package_name => { + required => { message => 'Package Name is required', status => 400 }, + }, + version_code => { + required => { message => 'Version Code is required', status => 400 }, + }, + version_number => { + required => { message => 'Version Number is required', status => 400 }, + }, + }; +}; + +sub post_feedback { + my $c = shift; + + my $validation = $c->validation; + $validation->input( $c->stash->{api_json} ); + + my $user_rs = $c->schema->resultset('User'); + + $validation->required('email')->in_reusltset( 'email', $user_rs ); + $validation->required('app_name'); + $validation->required('package_name'); + $validation->required('version_code'); + $validation->required('version_number'); + + return $c->api_validation_error if $validation->has_error; + + return $c->render( json => { + success => Mojo::JSON->true, + message => 'Thank you for your Feedback!', + }); +} + +1;