refactor(architecture): update example. (close #38)
This commit is contained in:
+10
-9
@@ -35,46 +35,47 @@ class PhotoRepositoryImpl extends PhotoRepository {
|
||||
);
|
||||
|
||||
@override
|
||||
FutureResult<void> addPhotoToFavorites(Photo photo) => Result.tryCatchAsync(
|
||||
FutureOrResult<void> addPhotoToFavorites(Photo photo) => Result.tryCatchAsync(
|
||||
() => _favoriteLocalDataSource.addPhotoToFavorites(photo),
|
||||
(error) => ClientException('Cannot add photo to favorites.'),
|
||||
);
|
||||
|
||||
@override
|
||||
FutureResult<bool> checkIfPhotoIsInFavorites(int id) => Result.tryCatchAsync(
|
||||
FutureOrResult<bool> checkIfPhotoIsInFavorites(int id) =>
|
||||
Result.tryCatchAsync(
|
||||
() => _favoriteLocalDataSource.checkIfPhotoIsInFavorites(id),
|
||||
(error) =>
|
||||
ClientException('Cannot check if photo `$id` is in favorites.'),
|
||||
);
|
||||
|
||||
@override
|
||||
FutureResult<void> deletePhotoFromFavorites(int id) => Result.tryCatchAsync(
|
||||
FutureOrResult<void> deletePhotoFromFavorites(int id) => Result.tryCatchAsync(
|
||||
() => _favoriteLocalDataSource.deletePhotoFromFavorites(id),
|
||||
(error) => ClientException('Cannot delete photo `$id` from favorites.'),
|
||||
);
|
||||
|
||||
@override
|
||||
FutureResult<Album> getAlbum(int id) => Result.tryCatchAsync(
|
||||
FutureOrResult<Album> getAlbum(int id) => Result.tryCatchAsync(
|
||||
() => _albumRemoteDataSource.getAlbum(id),
|
||||
(error) => ServerException('Cannot retrieve album $id.'),
|
||||
);
|
||||
|
||||
@override
|
||||
FutureResult<List<Album>> getAllAlbums({int? start, int? limit}) =>
|
||||
FutureOrResult<List<Album>> getAllAlbums({int? start, int? limit}) =>
|
||||
Result.tryCatchAsync(
|
||||
() => _albumRemoteDataSource.getAllAlbums(start: start, limit: limit),
|
||||
(error) => ServerException('Cannot retrieve all albums.'),
|
||||
);
|
||||
|
||||
@override
|
||||
FutureResult<List<Photo>> getAllPhotos({int? start, int? limit}) async =>
|
||||
FutureOrResult<List<Photo>> getAllPhotos({int? start, int? limit}) async =>
|
||||
Result.tryCatchAsync(
|
||||
() => _photoRemoteDataSource.getAllPhotos(start: start, limit: limit),
|
||||
(error) => ServerException('Cannot retrieve all photos.'),
|
||||
);
|
||||
|
||||
@override
|
||||
FutureResult<List<Photo>> getAllPhotosFromFavorites() async {
|
||||
FutureOrResult<List<Photo>> getAllPhotosFromFavorites() async {
|
||||
try {
|
||||
final response = <Photo>[];
|
||||
final favorites =
|
||||
@@ -95,13 +96,13 @@ class PhotoRepositoryImpl extends PhotoRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
FutureResult<Photo> getPhoto(int id) => Result.tryCatchAsync(
|
||||
FutureOrResult<Photo> getPhoto(int id) => Result.tryCatchAsync(
|
||||
() => _photoRemoteDataSource.getPhoto(id),
|
||||
(error) => ServerException('Cannot retrieve photo $id.'),
|
||||
);
|
||||
|
||||
@override
|
||||
FutureResult<List<Photo>> getPhotosFromAlbum(
|
||||
FutureOrResult<List<Photo>> getPhotosFromAlbum(
|
||||
int albumId, {
|
||||
int? start,
|
||||
int? limit,
|
||||
|
||||
Reference in New Issue
Block a user