-
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
1 parent
5ae9eb3
commit b6dd984
Showing
35 changed files
with
231 additions
and
121 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 0.0.4 | ||
|
||
* Added must and mustWith | ||
|
||
## 0.0.3 | ||
|
||
* Added Cascade Mode | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
class RegisterParamDto { | ||
String email; | ||
String password; | ||
String phone; | ||
String password; | ||
String confirmPassword; | ||
|
||
RegisterParamDto({ | ||
required this.email, | ||
required this.password, | ||
required this.phone, | ||
required this.password, | ||
required this.confirmPassword, | ||
}); | ||
|
||
factory RegisterParamDto.empty() => RegisterParamDto(email: '', password: '', phone: ''); | ||
factory RegisterParamDto.empty() => RegisterParamDto(email: '', password: '', phone: '', confirmPassword: ''); | ||
|
||
setEmail(String value) => email = value; | ||
|
||
setPassword(String value) => password = value; | ||
|
||
setConfirmPassword(String value) => confirmPassword = value; | ||
|
||
setPhone(String value) => phone = value; | ||
} |
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
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
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ part 'validator_builder.dart'; | |
|
||
class _PropSelector<E, TProp> { | ||
final TProp Function(E entity) selector; | ||
final LucidValidationBuilder<TProp> builder; | ||
final LucidValidationBuilder<TProp, E> builder; | ||
|
||
_PropSelector({required this.selector, required this.builder}); | ||
} | ||
|
@@ -27,8 +27,8 @@ abstract class LucidValidation<E> { | |
/// final validator = UserValidation(); | ||
/// validator.ruleFor((user) => user.email).validEmail(); | ||
/// ``` | ||
LucidValidationBuilder<TProp> ruleFor<TProp>(TProp Function(E entity) func, {String key = ''}) { | ||
final builder = LucidValidationBuilder<TProp>(key: key); | ||
LucidValidationBuilder<TProp, E> ruleFor<TProp>(TProp Function(E entity) func, {String key = ''}) { | ||
final builder = LucidValidationBuilder<TProp, E>(key: key); | ||
final propSelector = _PropSelector<E, TProp>(selector: func, builder: builder); | ||
|
||
_propSelectors.add(propSelector); | ||
|
@@ -46,7 +46,7 @@ abstract class LucidValidation<E> { | |
/// final emailValidator = validator.byField('email'); | ||
/// String? validationResult = emailValidator('[email protected]'); | ||
/// ``` | ||
String? Function(String?)? byField(String key) { | ||
String? Function(String?)? byField(E entity, String key) { | ||
final propSelector = _propSelectors | ||
.where( | ||
(propSelector) => propSelector.builder.key == key, | ||
|
@@ -58,9 +58,9 @@ abstract class LucidValidation<E> { | |
return (value) { | ||
if (value == null) return null; | ||
final builder = propSelector.builder; | ||
final rules = builder._rules.cast<RuleFunc<String>>(); | ||
final rules = builder._rules.cast<RuleFunc<String, E>>(); | ||
for (var rule in rules) { | ||
final result = rule(value); | ||
final result = rule(value, entity); | ||
|
||
if (!result.isValid) { | ||
return result.error.message; | ||
|
@@ -92,7 +92,7 @@ abstract class LucidValidation<E> { | |
final mode = propSelector.builder._mode; | ||
|
||
for (var rule in propSelector.builder._rules) { | ||
final result = rule(propValue); | ||
final result = rule(propValue, entity); | ||
|
||
if (!result.isValid) { | ||
errors.add(result.error); | ||
|
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
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.