This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
Foodloop-Server/lib/Pear/LocalLoop/Controller/Api/Feedback.pm

63 lines
1.9 KiB
Perl
Raw Normal View History

2017-07-24 12:20:22 +00:00
package Pear::LocalLoop::Controller::Api::Feedback;
use Mojo::Base 'Mojolicious::Controller';
has error_messages => sub {
return {
email => {
required => { message => 'Email is required', status => 400 },
2017-09-18 10:31:57 +00:00
in_resultset => { message => 'Email does not exist in database', status => 400 },
2017-07-24 12:20:22 +00:00
},
2017-07-24 13:55:05 +00:00
feedbacktext => {
required => { message => 'Feedback is required', status => 400 },
},
2017-07-24 12:20:22 +00:00
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');
2017-07-24 13:55:05 +00:00
$validation->required('email')->in_resultset( 'email', $user_rs );
$validation->required('feedbacktext');
2017-07-24 12:20:22 +00:00
$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;
2017-07-24 13:55:05 +00:00
my $user = $user_rs->find({'email' => $validation->param('email')});
$c->schema->resultset('Feedback')->create({
user => $user,
feedbacktext => $validation->param('feedbacktext'),
app_name => $validation->param('app_name'),
package_name => $validation->param('package_name'),
version_code => $validation->param('version_code'),
version_number => $validation->param('version_number'),
});
2017-07-24 12:20:22 +00:00
return $c->render( json => {
success => Mojo::JSON->true,
message => 'Thank you for your Feedback!',
});
}
1;