-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tw 2046 group name validation (#2119)
- Loading branch information
1 parent
e2dc5da
commit 91e7e6a
Showing
19 changed files
with
460 additions
and
71 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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'package:fluffychat/presentation/state/failure.dart'; | ||
import 'package:fluffychat/presentation/state/success.dart'; | ||
|
||
class VerifyNameSuccessViewState extends UIState {} | ||
|
||
class VerifyNameFailure extends FeatureFailure { | ||
const VerifyNameFailure(dynamic exception) : super(exception: exception); | ||
} |
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,21 @@ | ||
import 'package:equatable/equatable.dart'; | ||
|
||
abstract class VerifyNameException extends Equatable implements Exception { | ||
static const nameWithOnlySpace = 'The name cannot contain only spaces'; | ||
static const emptyName = 'The name cannot be empty'; | ||
|
||
final String? message; | ||
const VerifyNameException(this.message); | ||
|
||
@override | ||
List<Object?> get props => [message]; | ||
} | ||
|
||
class NameWithSpaceOnlyException extends VerifyNameException { | ||
const NameWithSpaceOnlyException() | ||
: super(VerifyNameException.nameWithOnlySpace); | ||
} | ||
|
||
class EmptyNameException extends VerifyNameException { | ||
const EmptyNameException() : super(VerifyNameException.emptyName); | ||
} |
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,20 @@ | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:fluffychat/app_state/failure.dart'; | ||
import 'package:fluffychat/app_state/success.dart'; | ||
import 'package:fluffychat/domain/app_state/validator/verify_name_view_state.dart'; | ||
import 'package:fluffychat/domain/model/verification/new_name_request.dart'; | ||
import 'package:fluffychat/domain/model/verification/validator.dart'; | ||
|
||
extension ListValidatorExtension on List<Validator> { | ||
Either<Failure, Success> getValidatorNameViewState( | ||
NewNameRequest newNameRequest, | ||
) { | ||
for (final validator in this) { | ||
final either = validator.validate(newNameRequest); | ||
if (either.isLeft()) { | ||
return either; | ||
} | ||
} | ||
return Right<Failure, Success>(VerifyNameSuccessViewState()); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
lib/domain/model/extensions/validator_failure_extension.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,15 @@ | ||
import 'package:fluffychat/domain/app_state/validator/verify_name_view_state.dart'; | ||
import 'package:fluffychat/domain/exception/verify_name_exception.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/l10n.dart'; | ||
|
||
extension ValidatorFailureExtension on VerifyNameFailure { | ||
String getMessage(BuildContext context) { | ||
if (exception is NameWithSpaceOnlyException || | ||
exception is EmptyNameException) { | ||
return L10n.of(context)!.thisFieldCannotBeBlank; | ||
} else { | ||
return ''; | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
lib/domain/model/verification/composite_name_validator.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,20 @@ | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:fluffychat/app_state/failure.dart'; | ||
import 'package:fluffychat/app_state/success.dart'; | ||
import 'package:fluffychat/domain/app_state/validator/verify_name_view_state.dart'; | ||
import 'package:fluffychat/domain/model/verification/new_name_request.dart'; | ||
import 'package:fluffychat/domain/model/verification/validator.dart'; | ||
import 'package:fluffychat/domain/model/extensions/list_validator_extension.dart'; | ||
|
||
class CompositeNameValidator extends Validator<NewNameRequest> { | ||
final List<Validator> _listValidator; | ||
|
||
CompositeNameValidator(this._listValidator); | ||
|
||
@override | ||
Either<Failure, Success> validate(NewNameRequest value) { | ||
return _listValidator.isNotEmpty | ||
? _listValidator.getValidatorNameViewState(value) | ||
: Right<Failure, Success>(VerifyNameSuccessViewState()); | ||
} | ||
} |
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,20 @@ | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:fluffychat/app_state/failure.dart'; | ||
import 'package:fluffychat/app_state/success.dart'; | ||
import 'package:fluffychat/domain/app_state/validator/verify_name_view_state.dart'; | ||
import 'package:fluffychat/domain/exception/verify_name_exception.dart'; | ||
import 'package:fluffychat/domain/model/verification/new_name_request.dart'; | ||
import 'package:fluffychat/domain/model/verification/validator.dart'; | ||
|
||
class EmptyNameValidator extends Validator<NewNameRequest> { | ||
@override | ||
Either<Failure, Success> validate(NewNameRequest value) { | ||
if (value.value == null || value.value!.isEmpty) { | ||
return const Left<Failure, Success>( | ||
VerifyNameFailure(EmptyNameException()), | ||
); | ||
} else { | ||
return Right<Failure, Success>(VerifyNameSuccessViewState()); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
lib/domain/model/verification/name_with_space_only_validator.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,22 @@ | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:fluffychat/app_state/failure.dart'; | ||
import 'package:fluffychat/app_state/success.dart'; | ||
import 'package:fluffychat/domain/app_state/validator/verify_name_view_state.dart'; | ||
import 'package:fluffychat/domain/exception/verify_name_exception.dart'; | ||
import 'package:fluffychat/domain/model/verification/new_name_request.dart'; | ||
import 'package:fluffychat/domain/model/verification/validator.dart'; | ||
|
||
class NameWithSpaceOnlyValidator extends Validator<NewNameRequest> { | ||
@override | ||
Either<Failure, Success> validate(NewNameRequest value) { | ||
if (value.value != null && | ||
value.value!.isNotEmpty && | ||
value.value!.trim().isEmpty) { | ||
return const Left<Failure, Success>( | ||
VerifyNameFailure(NameWithSpaceOnlyException()), | ||
); | ||
} else { | ||
return Right<Failure, Success>(VerifyNameSuccessViewState()); | ||
} | ||
} | ||
} |
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,10 @@ | ||
import 'package:equatable/equatable.dart'; | ||
|
||
class NewNameRequest with EquatableMixin { | ||
final String? value; | ||
|
||
NewNameRequest(this.value); | ||
|
||
@override | ||
List<Object?> get props => [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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:fluffychat/app_state/failure.dart'; | ||
import 'package:fluffychat/app_state/success.dart'; | ||
|
||
abstract class Validator<T> { | ||
Either<Failure, Success> validate(T 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:fluffychat/app_state/failure.dart'; | ||
import 'package:fluffychat/app_state/success.dart'; | ||
import 'package:fluffychat/domain/app_state/validator/verify_name_view_state.dart'; | ||
import 'package:fluffychat/domain/model/verification/composite_name_validator.dart'; | ||
import 'package:fluffychat/domain/model/verification/new_name_request.dart'; | ||
import 'package:fluffychat/domain/model/verification/validator.dart'; | ||
|
||
class VerifyNameInteractor { | ||
Either<Failure, Success> execute( | ||
String? newName, | ||
List<Validator> listValidator, | ||
) { | ||
try { | ||
return CompositeNameValidator(listValidator) | ||
.validate(NewNameRequest(newName)); | ||
} catch (exception) { | ||
return Left<Failure, Success>(VerifyNameFailure(exception)); | ||
} | ||
} | ||
} |
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.