-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
534 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
52 changes: 52 additions & 0 deletions
52
lib/src/validations/exclusive_between_datetime_validation.dart
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
part of 'validations.dart'; | ||
|
||
/// Extension on [LucidValidationBuilder] for [DateTime] properties to add a exclusive between validation. | ||
/// | ||
/// This extension adds an `inclusiveBetween` method that can be used to | ||
/// ensure that a date is exclusive between two specified dates. | ||
extension ExclusiveBetweenDatetimeValidation on SimpleValidationBuilder<DateTime> { | ||
/// Adds a validation rule that checks if the [DateTime] is greater than [comparison]. | ||
/// | ||
/// [start] is the date and time value must be greater than. | ||
/// [end] is the date and time value must be less than. | ||
/// [message] is the error message returned if the validation fails. | ||
/// [code] is an optional error code for translation purposes. | ||
/// | ||
/// Returns the [LucidValidationBuilder] to allow for method chaining. | ||
/// | ||
/// Example: | ||
/// ```dart | ||
/// ... | ||
/// .ruleFor((event) => event.start, key: 'start') // | ||
/// .exclusiveBetween(start: DateTime.now(), end: DateTime.now().add(Duration(days: 1))); | ||
/// ``` | ||
/// | ||
/// String format args: | ||
/// - **{PropertyName}**: The name of the property. | ||
/// - **{StartValue}**: The value must be greater than or equal to. | ||
/// - **{EndValue}**: The value must be less than or equal to. | ||
/// | ||
SimpleValidationBuilder<DateTime> exclusiveBetween({ | ||
required DateTime start, | ||
required DateTime end, | ||
String? message, | ||
String? code, | ||
}) { | ||
return use((value, entity) { | ||
if (value.isAfter(start) && value.isBefore(end)) return null; | ||
|
||
final currentCode = code ?? Language.code.exclusiveBetweenDatetime; | ||
final currentMessage = LucidValidation.global.languageManager.translate( | ||
currentCode, | ||
parameters: { | ||
'PropertyName': key, | ||
'StartValue': start.toString(), | ||
'EndValue': end.toString(), | ||
}, | ||
defaultMessage: message, | ||
); | ||
|
||
return ValidationException(message: currentMessage, code: currentCode); | ||
}); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
part of 'validations.dart'; | ||
|
||
/// Extension on [LucidValidationBuilder] for [DateTime] properties to add a greater than validation. | ||
/// | ||
/// This extension adds a `greaterThan` method that can be used to ensure that | ||
/// a date is greater than a specified date. | ||
extension GreaterThanDateTimeValidation on SimpleValidationBuilder<DateTime> { | ||
/// Adds a validation rule that checks if the [DateTime] is greater than [comparison]. | ||
/// | ||
/// [comparison] is the date and time value must be greater than. | ||
/// [message] is the error message returned if the validation fails. | ||
/// [code] is an optional error code for translation purposes. | ||
/// | ||
/// Returns the [LucidValidationBuilder] to allow for method chaining. | ||
/// | ||
/// Example: | ||
/// ```dart | ||
/// ... | ||
/// .ruleFor((event) => event.start, key: 'start') // | ||
/// .greaterThan(DateTime.now()); | ||
/// ``` | ||
/// | ||
/// String format args: | ||
/// - **{PropertyName}**: The name of the property. | ||
/// - **{ComparisonValue}**: The value to compare against. | ||
/// | ||
SimpleValidationBuilder<DateTime> greaterThan( | ||
DateTime comparison, { | ||
String? message, | ||
String? code, | ||
}) { | ||
return use((value, entity) { | ||
if (value.isAfter(comparison)) return null; | ||
|
||
final currentCode = code ?? Language.code.greaterThanDatetime; | ||
final currentMessage = LucidValidation.global.languageManager.translate( | ||
currentCode, | ||
parameters: { | ||
'PropertyName': key, | ||
'ComparisonValue': comparison.toString(), | ||
}, | ||
defaultMessage: message, | ||
); | ||
|
||
return ValidationException(message: currentMessage, code: currentCode); | ||
}); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
lib/src/validations/greater_than_or_equal_to_datetime_validation.dart
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
part of 'validations.dart'; | ||
|
||
/// Extension on [LucidValidationBuilder] for [DateTime] properties to add a greater than validation. | ||
/// | ||
/// This extension adds a `greaterThanOrEqualTo` method that can be used to ensure that | ||
/// a date is greater than or equal to a specified date. | ||
extension GreaterThanOrEqualToDateTimeValidation on SimpleValidationBuilder<DateTime> { | ||
/// Adds a validation rule that checks if the [DateTime] is greater than [comparison]. | ||
/// | ||
/// [comparison] is the date and time value must be greater than or equal. | ||
/// [message] is the error message returned if the validation fails. | ||
/// [code] is an optional error code for translation purposes. | ||
/// | ||
/// Returns the [LucidValidationBuilder] to allow for method chaining. | ||
/// | ||
/// Example: | ||
/// ```dart | ||
/// ... | ||
/// .ruleFor((event) => event.start, key: 'start') // | ||
/// .greaterThanOrEqualTo(DateTime.now()); | ||
/// ``` | ||
/// | ||
/// String format args: | ||
/// - **{PropertyName}**: The name of the property. | ||
/// - **{ComparisonValue}**: The value to compare against. | ||
/// | ||
SimpleValidationBuilder<DateTime> greaterThanOrEqualTo( | ||
DateTime comparison, { | ||
String? message, | ||
String? code, | ||
}) { | ||
return use((value, entity) { | ||
if (value.isAfter(comparison) || value.isAtSameMomentAs(comparison)) return null; | ||
|
||
final currentCode = code ?? Language.code.greaterThanOrEqualToDateTime; | ||
final currentMessage = LucidValidation.global.languageManager.translate( | ||
currentCode, | ||
parameters: { | ||
'PropertyName': key, | ||
'ComparisonValue': comparison.toString(), | ||
}, | ||
defaultMessage: message, | ||
); | ||
|
||
return ValidationException(message: currentMessage, code: currentCode); | ||
}); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
lib/src/validations/inclusive_between_datetime_validation.dart
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
part of 'validations.dart'; | ||
|
||
/// Extension on [LucidValidationBuilder] for [DateTime] properties to add a inclusive between validation. | ||
/// | ||
/// This extension adds an `inclusiveBetween` method that can be used to | ||
/// ensure that a date is inclusive between two specified dates. | ||
extension InclusiveBetweenDatetimeValidation on SimpleValidationBuilder<DateTime> { | ||
/// Adds a validation rule that checks if the [DateTime] is greater than [comparison]. | ||
/// | ||
/// [start] is the date and time value must be greater than or equal to. | ||
/// [end] is the date and time value must be less than or equal to. | ||
/// [message] is the error message returned if the validation fails. | ||
/// [code] is an optional error code for translation purposes. | ||
/// | ||
/// Returns the [LucidValidationBuilder] to allow for method chaining. | ||
/// | ||
/// Example: | ||
/// ```dart | ||
/// ... | ||
/// .ruleFor((event) => event.start, key: 'start') // | ||
/// .inclusiveBetween(start: DateTime.now(), end: DateTime.now().add(Duration(days: 1))); | ||
/// ``` | ||
/// | ||
/// String format args: | ||
/// - **{PropertyName}**: The name of the property. | ||
/// - **{StartValue}**: The value must be greater than or equal to. | ||
/// - **{EndValue}**: The value must be less than or equal to. | ||
/// | ||
SimpleValidationBuilder<DateTime> inclusiveBetween({ | ||
required DateTime start, | ||
required DateTime end, | ||
String? message, | ||
String? code, | ||
}) { | ||
return use((value, entity) { | ||
if (value.isAfter(start) || value.isAtSameMomentAs(start) && value.isBefore(end) || value.isAtSameMomentAs(end)) return null; | ||
|
||
final currentCode = code ?? Language.code.inclusiveBetweenDatetime; | ||
final currentMessage = LucidValidation.global.languageManager.translate( | ||
currentCode, | ||
parameters: { | ||
'PropertyName': key, | ||
'StartValue': start.toString(), | ||
'EndValue': end.toString(), | ||
}, | ||
defaultMessage: message, | ||
); | ||
|
||
return ValidationException(message: currentMessage, code: currentCode); | ||
}); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
part of 'validations.dart'; | ||
|
||
/// Extension on [LucidValidationBuilder] for [DateTime] properties to add a less than validation. | ||
/// | ||
/// This extension adds a `lessThan` method that can be used to ensure that | ||
/// a date is less than a specified date. | ||
extension LessThanDatetimeValidation on SimpleValidationBuilder<DateTime> { | ||
/// Adds a validation rule that checks if the [DateTime] is greater than [comparison]. | ||
/// | ||
/// [comparison] is the date and time value must be less than. | ||
/// [message] is the error message returned if the validation fails. | ||
/// [code] is an optional error code for translation purposes. | ||
/// | ||
/// Returns the [LucidValidationBuilder] to allow for method chaining. | ||
/// | ||
/// Example: | ||
/// ```dart | ||
/// ... | ||
/// .ruleFor((event) => event.end, key: 'start') // | ||
/// .lessThan(DateTime.now()); | ||
/// ``` | ||
/// | ||
/// String format args: | ||
/// - **{PropertyName}**: The name of the property. | ||
/// - **{ComparisonValue}**: The value to compare against. | ||
/// | ||
SimpleValidationBuilder<DateTime> lessThan( | ||
DateTime comparison, { | ||
String? message, | ||
String? code, | ||
}) { | ||
return use((value, entity) { | ||
if (value.isBefore(comparison)) return null; | ||
|
||
final currentCode = code ?? Language.code.lessThanDateTime; | ||
final currentMessage = LucidValidation.global.languageManager.translate( | ||
currentCode, | ||
parameters: { | ||
'PropertyName': key, | ||
'ComparisonValue': comparison.toString(), | ||
}, | ||
defaultMessage: message, | ||
); | ||
|
||
return ValidationException(message: currentMessage, code: currentCode); | ||
}); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
lib/src/validations/less_than_or_equal_to_datetime_validation.dart
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
part of 'validations.dart'; | ||
|
||
/// Extension on [LucidValidationBuilder] for [DateTime] properties to add a less than validation. | ||
/// | ||
/// This extension adds a `lessThanOrEqualTo` method that can be used to ensure that | ||
/// a date is less than or equal to a specified date. | ||
extension LessThanOrEqualToDatetimeValidation on SimpleValidationBuilder<DateTime> { | ||
/// Adds a validation rule that checks if the [DateTime] is greater than [comparison]. | ||
/// | ||
/// [comparison] is the date and time value must be less than or equal to. | ||
/// [message] is the error message returned if the validation fails. | ||
/// [code] is an optional error code for translation purposes. | ||
/// | ||
/// Returns the [LucidValidationBuilder] to allow for method chaining. | ||
/// | ||
/// Example: | ||
/// ```dart | ||
/// ... | ||
/// .ruleFor((event) => event.end, key: 'start') // | ||
/// .lessThanOrEqualTo(DateTime.now()); | ||
/// ``` | ||
/// | ||
/// String format args: | ||
/// - **{PropertyName}**: The name of the property. | ||
/// - **{ComparisonValue}**: The value to compare against. | ||
/// | ||
SimpleValidationBuilder<DateTime> lessThanOrEqualTo( | ||
DateTime comparison, { | ||
String? message, | ||
String? code, | ||
}) { | ||
return use((value, entity) { | ||
if (value.isBefore(comparison) || value.isAtSameMomentAs(comparison)) return null; | ||
|
||
final currentCode = code ?? Language.code.lessThanOrEqualToDateTime; | ||
final currentMessage = LucidValidation.global.languageManager.translate( | ||
currentCode, | ||
parameters: { | ||
'PropertyName': key, | ||
'ComparisonValue': comparison.toString(), | ||
}, | ||
defaultMessage: message, | ||
); | ||
|
||
return ValidationException(message: currentMessage, code: currentCode); | ||
}); | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.