Last active
July 26, 2019 14:38
-
-
Save jjn1056/18b7ae41955ef91ce1f034f8696ac9b1 to your computer and use it in GitHub Desktop.
another validation example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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