diff --git a/packages/wyatt_architecture/example/lib/data/repositories/photo_repository_impl.dart b/packages/wyatt_architecture/example/lib/data/repositories/photo_repository_impl.dart index 3f85aff2..7cec10fa 100644 --- a/packages/wyatt_architecture/example/lib/data/repositories/photo_repository_impl.dart +++ b/packages/wyatt_architecture/example/lib/data/repositories/photo_repository_impl.dart @@ -35,46 +35,47 @@ class PhotoRepositoryImpl extends PhotoRepository { ); @override - FutureResult addPhotoToFavorites(Photo photo) => Result.tryCatchAsync( + FutureOrResult addPhotoToFavorites(Photo photo) => Result.tryCatchAsync( () => _favoriteLocalDataSource.addPhotoToFavorites(photo), (error) => ClientException('Cannot add photo to favorites.'), ); @override - FutureResult checkIfPhotoIsInFavorites(int id) => Result.tryCatchAsync( + FutureOrResult checkIfPhotoIsInFavorites(int id) => + Result.tryCatchAsync( () => _favoriteLocalDataSource.checkIfPhotoIsInFavorites(id), (error) => ClientException('Cannot check if photo `$id` is in favorites.'), ); @override - FutureResult deletePhotoFromFavorites(int id) => Result.tryCatchAsync( + FutureOrResult deletePhotoFromFavorites(int id) => Result.tryCatchAsync( () => _favoriteLocalDataSource.deletePhotoFromFavorites(id), (error) => ClientException('Cannot delete photo `$id` from favorites.'), ); @override - FutureResult getAlbum(int id) => Result.tryCatchAsync( + FutureOrResult getAlbum(int id) => Result.tryCatchAsync( () => _albumRemoteDataSource.getAlbum(id), (error) => ServerException('Cannot retrieve album $id.'), ); @override - FutureResult> getAllAlbums({int? start, int? limit}) => + FutureOrResult> getAllAlbums({int? start, int? limit}) => Result.tryCatchAsync( () => _albumRemoteDataSource.getAllAlbums(start: start, limit: limit), (error) => ServerException('Cannot retrieve all albums.'), ); @override - FutureResult> getAllPhotos({int? start, int? limit}) async => + FutureOrResult> getAllPhotos({int? start, int? limit}) async => Result.tryCatchAsync( () => _photoRemoteDataSource.getAllPhotos(start: start, limit: limit), (error) => ServerException('Cannot retrieve all photos.'), ); @override - FutureResult> getAllPhotosFromFavorites() async { + FutureOrResult> getAllPhotosFromFavorites() async { try { final response = []; final favorites = @@ -95,13 +96,13 @@ class PhotoRepositoryImpl extends PhotoRepository { } @override - FutureResult getPhoto(int id) => Result.tryCatchAsync( + FutureOrResult getPhoto(int id) => Result.tryCatchAsync( () => _photoRemoteDataSource.getPhoto(id), (error) => ServerException('Cannot retrieve photo $id.'), ); @override - FutureResult> getPhotosFromAlbum( + FutureOrResult> getPhotosFromAlbum( int albumId, { int? start, int? limit, diff --git a/packages/wyatt_architecture/example/lib/domain/repositories/photo_repository.dart b/packages/wyatt_architecture/example/lib/domain/repositories/photo_repository.dart index b57b4689..7bc195ea 100644 --- a/packages/wyatt_architecture/example/lib/domain/repositories/photo_repository.dart +++ b/packages/wyatt_architecture/example/lib/domain/repositories/photo_repository.dart @@ -19,17 +19,17 @@ import 'package:architecture_example/domain/entities/photo.dart'; import 'package:wyatt_architecture/wyatt_architecture.dart'; abstract class PhotoRepository extends BaseRepository { - FutureResult getAlbum(int id); - FutureResult> getAllAlbums({int? start, int? limit}); - FutureResult getPhoto(int id); - FutureResult> getAllPhotos({int? start, int? limit}); - FutureResult> getPhotosFromAlbum( + FutureOrResult getAlbum(int id); + FutureOrResult> getAllAlbums({int? start, int? limit}); + FutureOrResult getPhoto(int id); + FutureOrResult> getAllPhotos({int? start, int? limit}); + FutureOrResult> getPhotosFromAlbum( int albumId, { int? start, int? limit, }); - FutureResult addPhotoToFavorites(Photo photo); - FutureResult deletePhotoFromFavorites(int id); - FutureResult> getAllPhotosFromFavorites(); - FutureResult checkIfPhotoIsInFavorites(int id); + FutureOrResult addPhotoToFavorites(Photo photo); + FutureOrResult deletePhotoFromFavorites(int id); + FutureOrResult> getAllPhotosFromFavorites(); + FutureOrResult checkIfPhotoIsInFavorites(int id); } diff --git a/packages/wyatt_architecture/example/lib/domain/usecases/photos/add_photo_to_favorites.dart b/packages/wyatt_architecture/example/lib/domain/usecases/photos/add_photo_to_favorites.dart index 7e88cdc3..7a936d44 100644 --- a/packages/wyatt_architecture/example/lib/domain/usecases/photos/add_photo_to_favorites.dart +++ b/packages/wyatt_architecture/example/lib/domain/usecases/photos/add_photo_to_favorites.dart @@ -1,31 +1,40 @@ // Copyright (C) 2022 WYATT GROUP // Please see the AUTHORS file for details. -// +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program. If not, see . +import 'dart:async'; + import 'package:architecture_example/domain/entities/photo.dart'; import 'package:architecture_example/domain/repositories/photo_repository.dart'; import 'package:wyatt_architecture/wyatt_architecture.dart'; -class AddPhotoToFavorites extends UseCase> { +class AddPhotoToFavorites extends AsyncUseCase> { final PhotoRepository _photoRepository; AddPhotoToFavorites(this._photoRepository); @override - FutureResult> call(Photo params) async { - await _photoRepository.addPhotoToFavorites(params); + FutureOrResult> call(Photo? params) async { + await _photoRepository.addPhotoToFavorites(params!); return _photoRepository.getAllPhotosFromFavorites(); } + + @override + FutureOr onStart(Photo? params) { + if (params == null) { + throw ClientException('Photo cannot be null'); + } + } } diff --git a/packages/wyatt_architecture/example/lib/domain/usecases/photos/check_if_photo_is_in_favorites.dart b/packages/wyatt_architecture/example/lib/domain/usecases/photos/check_if_photo_is_in_favorites.dart index d955d4f1..1bb9efd9 100644 --- a/packages/wyatt_architecture/example/lib/domain/usecases/photos/check_if_photo_is_in_favorites.dart +++ b/packages/wyatt_architecture/example/lib/domain/usecases/photos/check_if_photo_is_in_favorites.dart @@ -14,15 +14,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +import 'dart:async'; + import 'package:architecture_example/domain/repositories/photo_repository.dart'; import 'package:wyatt_architecture/wyatt_architecture.dart'; -class CheckIfPhotoIsInFavorites extends UseCase { +class CheckIfPhotoIsInFavorites extends AsyncUseCase { final PhotoRepository _photoRepository; CheckIfPhotoIsInFavorites(this._photoRepository); @override - FutureResult call(int params) async => - _photoRepository.checkIfPhotoIsInFavorites(params); + FutureOrResult call(int? params) async => + _photoRepository.checkIfPhotoIsInFavorites(params!); + + @override + FutureOr onStart(int? params) { + if (params == null) { + throw ClientException('id cannot be null'); + } + } } diff --git a/packages/wyatt_architecture/example/lib/domain/usecases/photos/display_favorites.dart b/packages/wyatt_architecture/example/lib/domain/usecases/photos/display_favorites.dart index 545c09e5..733e2dbd 100644 --- a/packages/wyatt_architecture/example/lib/domain/usecases/photos/display_favorites.dart +++ b/packages/wyatt_architecture/example/lib/domain/usecases/photos/display_favorites.dart @@ -1,16 +1,16 @@ // Copyright (C) 2022 WYATT GROUP // Please see the AUTHORS file for details. -// +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program. If not, see . @@ -18,13 +18,13 @@ import 'package:architecture_example/domain/entities/photo.dart'; import 'package:architecture_example/domain/repositories/photo_repository.dart'; import 'package:wyatt_architecture/wyatt_architecture.dart'; -class DisplayFavorites extends UseCase> { +class DisplayFavorites extends AsyncUseCase> { final PhotoRepository _photoRepository; DisplayFavorites(this._photoRepository); @override - FutureResult> call(void params) { + FutureOrResult> call(void params) { final photos = _photoRepository.getAllPhotosFromFavorites(); return photos; } diff --git a/packages/wyatt_architecture/example/lib/domain/usecases/photos/display_photo.dart b/packages/wyatt_architecture/example/lib/domain/usecases/photos/display_photo.dart index 3c5da43d..3a41eeb2 100644 --- a/packages/wyatt_architecture/example/lib/domain/usecases/photos/display_photo.dart +++ b/packages/wyatt_architecture/example/lib/domain/usecases/photos/display_photo.dart @@ -14,18 +14,27 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +import 'dart:async'; + import 'package:architecture_example/domain/entities/photo.dart'; import 'package:architecture_example/domain/repositories/photo_repository.dart'; import 'package:wyatt_architecture/wyatt_architecture.dart'; -class DisplayPhoto extends UseCase { +class DisplayPhoto extends AsyncUseCase { final PhotoRepository _photoRepository; DisplayPhoto(this._photoRepository); @override - FutureResult call(int params) { - final photo = _photoRepository.getPhoto(params); + FutureOrResult call(int? params) { + final photo = _photoRepository.getPhoto(params!); return photo; } + + @override + FutureOr onStart(int? params) { + if (params == null) { + throw ClientException('id cannot be null'); + } + } } diff --git a/packages/wyatt_architecture/example/lib/domain/usecases/photos/open_album.dart b/packages/wyatt_architecture/example/lib/domain/usecases/photos/open_album.dart index 926d5331..a1053a15 100644 --- a/packages/wyatt_architecture/example/lib/domain/usecases/photos/open_album.dart +++ b/packages/wyatt_architecture/example/lib/domain/usecases/photos/open_album.dart @@ -14,24 +14,33 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +import 'dart:async'; + import 'package:architecture_example/domain/entities/photo.dart'; import 'package:architecture_example/domain/repositories/photo_repository.dart'; import 'package:architecture_example/domain/usecases/photos/params/query_parameters.dart'; import 'package:wyatt_architecture/wyatt_architecture.dart'; -class OpenAlbum extends UseCase> { +class OpenAlbum extends AsyncUseCase> { final PhotoRepository _photoRepository; OpenAlbum(this._photoRepository); @override - FutureResult> call(QueryParameters params) { + FutureOrResult> call(QueryParameters? params) { final photos = _photoRepository.getPhotosFromAlbum( - params.albumId, + params!.albumId, start: params.start, limit: params.limit, ); return photos; } + + @override + FutureOr onStart(QueryParameters? params) { + if (params == null) { + throw ClientException('params cannot be null'); + } + } } diff --git a/packages/wyatt_architecture/example/lib/domain/usecases/photos/remove_photo_from_favorites.dart b/packages/wyatt_architecture/example/lib/domain/usecases/photos/remove_photo_from_favorites.dart index 90012646..e706beea 100644 --- a/packages/wyatt_architecture/example/lib/domain/usecases/photos/remove_photo_from_favorites.dart +++ b/packages/wyatt_architecture/example/lib/domain/usecases/photos/remove_photo_from_favorites.dart @@ -14,18 +14,27 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +import 'dart:async'; + import 'package:architecture_example/domain/entities/photo.dart'; import 'package:architecture_example/domain/repositories/photo_repository.dart'; import 'package:wyatt_architecture/wyatt_architecture.dart'; -class RemovePhotoFromFavorites extends UseCase> { +class RemovePhotoFromFavorites extends AsyncUseCase> { final PhotoRepository _photoRepository; RemovePhotoFromFavorites(this._photoRepository); @override - FutureResult> call(int params) async { - await _photoRepository.deletePhotoFromFavorites(params); + FutureOrResult> call(int? params) async { + await _photoRepository.deletePhotoFromFavorites(params!); return _photoRepository.getAllPhotosFromFavorites(); } + + @override + FutureOr onStart(int? params) { + if (params == null) { + throw ClientException('id cannot be null'); + } + } } diff --git a/packages/wyatt_architecture/example/lib/domain/usecases/photos/retrieve_all_albums.dart b/packages/wyatt_architecture/example/lib/domain/usecases/photos/retrieve_all_albums.dart index c8a02e86..560abe93 100644 --- a/packages/wyatt_architecture/example/lib/domain/usecases/photos/retrieve_all_albums.dart +++ b/packages/wyatt_architecture/example/lib/domain/usecases/photos/retrieve_all_albums.dart @@ -14,22 +14,31 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +import 'dart:async'; + import 'package:architecture_example/domain/entities/album.dart'; import 'package:architecture_example/domain/repositories/photo_repository.dart'; import 'package:architecture_example/domain/usecases/photos/params/query_parameters.dart'; import 'package:wyatt_architecture/wyatt_architecture.dart'; -class RetrieveAllAlbums extends UseCase> { +class RetrieveAllAlbums extends AsyncUseCase> { final PhotoRepository _photoRepository; RetrieveAllAlbums(this._photoRepository); @override - FutureResult> call(QueryParameters params) { + FutureOrResult> call(QueryParameters? params) { final albums = _photoRepository.getAllAlbums( - start: params.start, + start: params!.start, limit: params.limit, ); return albums; } + + @override + FutureOr onStart(QueryParameters? params) { + if (params == null) { + throw ClientException('params cannot be null'); + } + } }