Remove post user/day, and reformat validators

This commit is contained in:
Tom Bloor 2017-09-08 12:46:54 +01:00
parent c6679e1261
commit 4176c61c00
4 changed files with 44 additions and 53 deletions

View file

@ -74,16 +74,6 @@ 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;
@ -150,7 +140,6 @@ sub startup {
$api->post('/search')->to('api-upload#post_search');
$api->post('/user')->to('api-user#post_account');
$api->post('/user/account')->to('api-user#post_account_update');
$api->post('/user/day')->to('api-user#post_day');
$api->post('/user-history')->to('api-user#post_user_history');
$api->post('/stats')->to('api-stats#post_index');
$api->post('/stats/leaderboard')->to('api-stats#post_leaderboards');

View file

@ -39,22 +39,6 @@ has error_messages => sub {
};
};
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,
});
}
sub post_account {
my $c = shift;

View file

@ -7,34 +7,52 @@ sub register {
my ( $plugin, $app, $conf ) = @_;
$app->helper( iso_datetime_parser => sub {
return DateTime::Format::Strptime->new( pattern => '%Y-%m-%dT%H:%M:%S.%3N%z' );
});
return DateTime::Format::Strptime->new( pattern => '%Y-%m-%dT%H:%M:%S.%3N%z' );
});
$app->helper( parse_iso_datetime => sub {
my ( $c, $date_string ) = @_;
return $c->iso_datetime_parser->parse_datetime(
$date_string,
);
});
$app->helper( iso_date_parser => sub {
return DateTime::Format::Strptime->new( pattern => '%Y-%m-%d' );
});
$app->helper( format_iso_datetime => sub {
my ( $c, $datetime_obj ) = @_;
return $c->iso_datetime_parser->parse_datetime(
$datetime_obj,
);
});
$app->helper( parse_iso_date => sub {
my ( $c, $date_string ) = @_;
return $c->iso_date_parser->parse_datetime(
$date_string,
);
});
$app->helper( db_datetime_parser => sub {
return shift->schema->storage->datetime_parser;
});
$app->helper( format_iso_date => sub {
my ( $c, $datetime_obj ) = @_;
return $c->iso_date_parser->format_datetime(
$datetime_obj,
);
});
$app->helper( format_db_datetime => sub {
my ( $c, $datetime_obj ) = @_;
$datetime_obj->set_time_zone('UTC');
return $c->db_datetime_parser->format_datetime(
$datetime_obj,
);
});
$app->helper( parse_iso_datetime => sub {
my ( $c, $date_string ) = @_;
return $c->iso_datetime_parser->parse_datetime(
$date_string,
);
});
$app->helper( format_iso_datetime => sub {
my ( $c, $datetime_obj ) = @_;
return $c->iso_datetime_parser->format_datetime(
$datetime_obj,
);
});
$app->helper( db_datetime_parser => sub {
return shift->schema->storage->datetime_parser;
});
$app->helper( format_db_datetime => sub {
my ( $c, $datetime_obj ) = @_;
$datetime_obj->set_time_zone('UTC');
return $c->db_datetime_parser->format_datetime(
$datetime_obj,
);
});
}

View file

@ -53,9 +53,9 @@ sub register {
return $app->types->type($extension) eq $filetype ? undef : 1;
});
$app->validator->add_check( is_iso_datetime => sub {
$app->validator->add_check( is_iso_date => sub {
my ( $validation, $name, $value ) = @_;
$value = $app->datetime_formatter->parse_datetime( $value );
$value = $app->iso_date_parser->parse_datetime( $value );
return defined $value ? undef : 1;
});