refactor(architecture): update naming methodes (close #47)

This commit is contained in:
AN12345 2022-11-24 17:25:44 -05:00
parent 3886ef080e
commit 17e7bce9e6
9 changed files with 12 additions and 12 deletions

View File

@ -141,7 +141,7 @@ class SearchPhotos extends StreamUseCase<QueryParameters, List<Photo>>> {
On this case, observers allow you to add alternative scénarios when data changed, overriding `onData` or `onDone`. On this case, observers allow you to add alternative scénarios when data changed, overriding `onData` or `onDone`.
Please note that to use handlers, call `execute` methodes instead of `call`. Please note that to use handlers, call `call` method and not `execute`.
> In fact, here we need a new parameter object, so let's create it: > In fact, here we need a new parameter object, so let's create it:

View File

@ -26,7 +26,7 @@ class AddPhotoToFavorites extends AsyncUseCase<Photo, List<Photo>> {
AddPhotoToFavorites(this._photoRepository); AddPhotoToFavorites(this._photoRepository);
@override @override
FutureOrResult<List<Photo>> call(Photo? params) async { FutureOrResult<List<Photo>> execute(Photo? params) async {
await _photoRepository.addPhotoToFavorites(params!); await _photoRepository.addPhotoToFavorites(params!);
return _photoRepository.getAllPhotosFromFavorites(); return _photoRepository.getAllPhotosFromFavorites();
} }

View File

@ -25,7 +25,7 @@ class CheckIfPhotoIsInFavorites extends AsyncUseCase<int, bool> {
CheckIfPhotoIsInFavorites(this._photoRepository); CheckIfPhotoIsInFavorites(this._photoRepository);
@override @override
FutureOrResult<bool> call(int? params) async => FutureOrResult<bool> execute(int? params) async =>
_photoRepository.checkIfPhotoIsInFavorites(params!); _photoRepository.checkIfPhotoIsInFavorites(params!);
@override @override

View File

@ -24,7 +24,7 @@ class DisplayFavorites extends AsyncUseCase<NoParam, List<Photo>> {
DisplayFavorites(this._photoRepository); DisplayFavorites(this._photoRepository);
@override @override
FutureOrResult<List<Photo>> call(void params) { FutureOrResult<List<Photo>> execute(void params) {
final photos = _photoRepository.getAllPhotosFromFavorites(); final photos = _photoRepository.getAllPhotosFromFavorites();
return photos; return photos;
} }

View File

@ -26,7 +26,7 @@ class DisplayPhoto extends AsyncUseCase<int, Photo> {
DisplayPhoto(this._photoRepository); DisplayPhoto(this._photoRepository);
@override @override
FutureOrResult<Photo> call(int? params) { FutureOrResult<Photo> execute(int? params) {
final photo = _photoRepository.getPhoto(params!); final photo = _photoRepository.getPhoto(params!);
return photo; return photo;
} }

View File

@ -27,7 +27,7 @@ class OpenAlbum extends AsyncUseCase<QueryParameters, List<Photo>> {
OpenAlbum(this._photoRepository); OpenAlbum(this._photoRepository);
@override @override
FutureOrResult<List<Photo>> call(QueryParameters? params) { FutureOrResult<List<Photo>> execute(QueryParameters? params) {
final photos = _photoRepository.getPhotosFromAlbum( final photos = _photoRepository.getPhotosFromAlbum(
params!.albumId, params!.albumId,
start: params.start, start: params.start,

View File

@ -26,7 +26,7 @@ class RemovePhotoFromFavorites extends AsyncUseCase<int, List<Photo>> {
RemovePhotoFromFavorites(this._photoRepository); RemovePhotoFromFavorites(this._photoRepository);
@override @override
FutureOrResult<List<Photo>> call(int? params) async { FutureOrResult<List<Photo>> execute(int? params) async {
await _photoRepository.deletePhotoFromFavorites(params!); await _photoRepository.deletePhotoFromFavorites(params!);
return _photoRepository.getAllPhotosFromFavorites(); return _photoRepository.getAllPhotosFromFavorites();
} }

View File

@ -27,7 +27,7 @@ class RetrieveAllAlbums extends AsyncUseCase<QueryParameters, List<Album>> {
RetrieveAllAlbums(this._photoRepository); RetrieveAllAlbums(this._photoRepository);
@override @override
FutureOrResult<List<Album>> call(QueryParameters? params) { FutureOrResult<List<Album>> execute(QueryParameters? params) {
final albums = _photoRepository.getAllAlbums( final albums = _photoRepository.getAllAlbums(
start: params!.start, start: params!.start,
limit: params.limit, limit: params.limit,

View File

@ -26,11 +26,11 @@ typedef StreamResult<T> = Stream<Result<T, AppException>>;
/// Abstract class of a use case /// Abstract class of a use case
abstract class BaseUseCase<Parameters, ReturnType> { abstract class BaseUseCase<Parameters, ReturnType> {
/// Run use case scenarios /// Run use case scenarios
ReturnType execute(Parameters parameters); ReturnType call(Parameters parameters);
/// Private function to implement main scenario /// Private function to implement main scenario
/// of your usecase. /// of your usecase.
ReturnType call(Parameters params); ReturnType execute(Parameters params);
} }
/// Abstract class of a use case that deals specifically /// Abstract class of a use case that deals specifically
@ -43,10 +43,10 @@ abstract class UseCase<Parameters, ReturnType>
/// Supports the result of the main scenario and integrates /// Supports the result of the main scenario and integrates
/// some alternative scenarios if necessary. /// some alternative scenarios if necessary.
@override @override
FutureOrResult<ReturnType> execute(Parameters? parameters) async { FutureOrResult<ReturnType> call(Parameters? parameters) async {
try { try {
await onStart(parameters); await onStart(parameters);
final response = await call(parameters); final response = await execute(parameters);
if (response.isErr) { if (response.isErr) {
await onError(response.err); await onError(response.err);
} else if (response.isOk && response.ok != null) { } else if (response.isOk && response.ok != null) {