Skip to content

Instantly share code, notes, and snippets.

@jjn1056
Last active July 26, 2019 14:38
Show Gist options
  • Save jjn1056/18b7ae41955ef91ce1f034f8696ac9b1 to your computer and use it in GitHub Desktop.
Save jjn1056/18b7ae41955ef91ce1f034f8696ac9b1 to your computer and use it in GitHub Desktop.
another validation example
$c->req->data('name', 'Invalid Name')
->exists
->defined
->size(3,10)
->json(',num')
$c->res->http_ok->json($data);
sub add_user :PostAt(/user) ($self, $c) {
my $data = $c->data->bind(sub {$c->model->create(%_)} )
->field('name', 'Invalid Name')
->exists
->defined
->size(3,10)
->html_escape
->json(',num')
->detach_if_errors;
return $c->http_ok
->json($data->escaped);
}
sub update_user :PostAt(/user/{id}) ($self, $c) {
my $user = $c->model->find($_{id});
my $data = $c->data->bind($user)
->field('name', 'Invalid Name')
->exists
->defined
->size(3,10)
->html_escape
->json(',num')
->detach_if_errors;
return $c->http_ok
->json($data->escaped);
}
sub end :Private ($self, $c) {
if(my $err = $c->errors) {
return $c->http_nok->json($err);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment