Started on user day entry
This commit is contained in:
parent
b03b7ccc5f
commit
1598909958
6 changed files with 142 additions and 1 deletions
|
@ -69,6 +69,16 @@ sub startup {
|
|||
}
|
||||
});
|
||||
|
||||
$self->helper( datetime_formatter => sub {
|
||||
my $c = shift;
|
||||
|
||||
return DateTime::Format::Strptime->new(
|
||||
pattern => '%FT%T%z',
|
||||
strict => 1,
|
||||
on_error => 'undef',
|
||||
);
|
||||
});
|
||||
|
||||
$self->helper( get_path_from_uuid => sub {
|
||||
my $c = shift;
|
||||
my $uuid = shift;
|
||||
|
@ -120,6 +130,7 @@ sub startup {
|
|||
});
|
||||
$api->post('/upload')->to('api-upload#post_upload');
|
||||
$api->post('/search')->to('api-upload#post_search');
|
||||
$api->post('/user/day')->to('api-user#post_day');
|
||||
$api->post('/edit')->to('api-api#post_edit');
|
||||
$api->post('/fetchuser')->to('api-api#post_fetchuser');
|
||||
$api->post('/user-history')->to('api-user#post_user_history');
|
||||
|
|
|
@ -1,5 +1,34 @@
|
|||
package Pear::LocalLoop::Controller::Api::User;
|
||||
use Mojo::Base 'Mojolicious::Controller';
|
||||
use Mojo::JSON;
|
||||
|
||||
has error_messages => sub {
|
||||
return {
|
||||
day => {
|
||||
is_iso_datetime => { message => 'Invalid ISO8601 Datetime', status => 400 },
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
sub post_day {
|
||||
my $c = shift;
|
||||
|
||||
my $validation = $c->validation;
|
||||
|
||||
$validation->input( $c->stash->{api_json} );
|
||||
|
||||
$validation->optional('day')->is_iso_datetime;
|
||||
|
||||
return $c->api_validation_error if $validation->has_error;
|
||||
|
||||
$c->render( json => {
|
||||
success => Mojo::JSON->true,
|
||||
});
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
use Data::Dumper;
|
||||
use Mojo::JSON;
|
||||
use DateTime;
|
||||
|
|
|
@ -5,6 +5,7 @@ use Email::Valid;
|
|||
use Geo::UK::Postcode;
|
||||
use Scalar::Util qw/ looks_like_number /;
|
||||
use File::Basename;
|
||||
use DateTime::Format::Strptime;
|
||||
|
||||
sub register {
|
||||
my ( $plugin, $app, $conf ) = @_;
|
||||
|
@ -45,6 +46,12 @@ sub register {
|
|||
$extension =~ s/^\.//;
|
||||
return $app->types->type($extension) eq $filetype ? undef : 1;
|
||||
});
|
||||
|
||||
$app->validator->add_check( is_iso_datetime => sub {
|
||||
my ( $validation, $name, $value ) = @_;
|
||||
$value = $app->datetime_formatter->parse_datetime( $value );
|
||||
return defined $value ? undef : 1;
|
||||
});
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
Reference in a new issue