refactor(architecture): update naming methodes (close #47)
This commit is contained in:
parent
3886ef080e
commit
17e7bce9e6
@ -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`.
|
||||
|
||||
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:
|
||||
|
||||
|
@ -26,7 +26,7 @@ class AddPhotoToFavorites extends AsyncUseCase<Photo, List<Photo>> {
|
||||
AddPhotoToFavorites(this._photoRepository);
|
||||
|
||||
@override
|
||||
FutureOrResult<List<Photo>> call(Photo? params) async {
|
||||
FutureOrResult<List<Photo>> execute(Photo? params) async {
|
||||
await _photoRepository.addPhotoToFavorites(params!);
|
||||
return _photoRepository.getAllPhotosFromFavorites();
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class CheckIfPhotoIsInFavorites extends AsyncUseCase<int, bool> {
|
||||
CheckIfPhotoIsInFavorites(this._photoRepository);
|
||||
|
||||
@override
|
||||
FutureOrResult<bool> call(int? params) async =>
|
||||
FutureOrResult<bool> execute(int? params) async =>
|
||||
_photoRepository.checkIfPhotoIsInFavorites(params!);
|
||||
|
||||
@override
|
||||
|
@ -24,7 +24,7 @@ class DisplayFavorites extends AsyncUseCase<NoParam, List<Photo>> {
|
||||
DisplayFavorites(this._photoRepository);
|
||||
|
||||
@override
|
||||
FutureOrResult<List<Photo>> call(void params) {
|
||||
FutureOrResult<List<Photo>> execute(void params) {
|
||||
final photos = _photoRepository.getAllPhotosFromFavorites();
|
||||
return photos;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ class DisplayPhoto extends AsyncUseCase<int, Photo> {
|
||||
DisplayPhoto(this._photoRepository);
|
||||
|
||||
@override
|
||||
FutureOrResult<Photo> call(int? params) {
|
||||
FutureOrResult<Photo> execute(int? params) {
|
||||
final photo = _photoRepository.getPhoto(params!);
|
||||
return photo;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ class OpenAlbum extends AsyncUseCase<QueryParameters, List<Photo>> {
|
||||
OpenAlbum(this._photoRepository);
|
||||
|
||||
@override
|
||||
FutureOrResult<List<Photo>> call(QueryParameters? params) {
|
||||
FutureOrResult<List<Photo>> execute(QueryParameters? params) {
|
||||
final photos = _photoRepository.getPhotosFromAlbum(
|
||||
params!.albumId,
|
||||
start: params.start,
|
||||
|
@ -26,7 +26,7 @@ class RemovePhotoFromFavorites extends AsyncUseCase<int, List<Photo>> {
|
||||
RemovePhotoFromFavorites(this._photoRepository);
|
||||
|
||||
@override
|
||||
FutureOrResult<List<Photo>> call(int? params) async {
|
||||
FutureOrResult<List<Photo>> execute(int? params) async {
|
||||
await _photoRepository.deletePhotoFromFavorites(params!);
|
||||
return _photoRepository.getAllPhotosFromFavorites();
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ class RetrieveAllAlbums extends AsyncUseCase<QueryParameters, List<Album>> {
|
||||
RetrieveAllAlbums(this._photoRepository);
|
||||
|
||||
@override
|
||||
FutureOrResult<List<Album>> call(QueryParameters? params) {
|
||||
FutureOrResult<List<Album>> execute(QueryParameters? params) {
|
||||
final albums = _photoRepository.getAllAlbums(
|
||||
start: params!.start,
|
||||
limit: params.limit,
|
||||
|
@ -26,11 +26,11 @@ typedef StreamResult<T> = Stream<Result<T, AppException>>;
|
||||
/// Abstract class of a use case
|
||||
abstract class BaseUseCase<Parameters, ReturnType> {
|
||||
/// Run use case scenarios
|
||||
ReturnType execute(Parameters parameters);
|
||||
ReturnType call(Parameters parameters);
|
||||
|
||||
/// Private function to implement main scenario
|
||||
/// of your usecase.
|
||||
ReturnType call(Parameters params);
|
||||
ReturnType execute(Parameters params);
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// some alternative scenarios if necessary.
|
||||
@override
|
||||
FutureOrResult<ReturnType> execute(Parameters? parameters) async {
|
||||
FutureOrResult<ReturnType> call(Parameters? parameters) async {
|
||||
try {
|
||||
await onStart(parameters);
|
||||
final response = await call(parameters);
|
||||
final response = await execute(parameters);
|
||||
if (response.isErr) {
|
||||
await onError(response.err);
|
||||
} else if (response.isOk && response.ok != null) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user