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

77 lines
2.3 KiB
Perl
Raw Permalink 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 {
2021-03-20 12:09:50 +00:00
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"
},
},
feedbacktext => {
required => { message => 'Feedback is required', 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 },
},
};
2017-07-24 12:20:22 +00:00
};
sub post_feedback {
2021-03-20 12:09:50 +00:00
my $c = shift;
2017-07-24 12:20:22 +00:00
2021-03-20 12:09:50 +00:00
my $validation = $c->validation;
$validation->input( $c->stash->{api_json} );
2017-07-24 12:20:22 +00:00
2021-03-20 12:09:50 +00:00
my $user_rs = $c->schema->resultset('User');
2017-07-24 12:20:22 +00:00
2021-03-20 12:09:50 +00:00
$validation->required('email')->in_resultset( 'email', $user_rs );
$validation->required( 'feedbacktext', 'not_empty' );
$validation->required('app_name');
$validation->required('package_name');
$validation->required('version_code');
$validation->required('version_number');
2017-07-24 12:20:22 +00:00
2021-03-20 12:09:50 +00:00
return $c->api_validation_error if $validation->has_error;
2017-07-24 12:20:22 +00:00
2021-03-20 12:09:50 +00:00
my $user = $user_rs->find( { 'email' => $validation->param('email') } );
2017-07-24 13:55:05 +00:00
2021-03-20 12:09:50 +00:00
$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 13:55:05 +00:00
2021-03-20 12:09:50 +00:00
return $c->render(
json => {
success => Mojo::JSON->true,
message => 'Thank you for your Feedback!',
}
);
2017-07-24 12:20:22 +00:00
}
1;