docs(wyatt_architecture): update readme

This commit is contained in:
Hugo Pointcheval 2024-02-18 23:00:01 +01:00
parent 08218f7080
commit 1492745e54
Signed by: hugo
GPG Key ID: 3AAC487E131E00BC

View File

@ -50,10 +50,10 @@ class Photo extends Entity {
} }
``` ```
Then create the data sources by extending `BaseLocalDataSource` or `BaseRemoteDataSource` depending the type of data source. Then create the data sources by extending `BaseDataSource` :
```dart ```dart
abstract class PhotoRemoteDataSource extends BaseRemoteDataSource { abstract class PhotoRemoteDataSource extends BaseDataSource {
Future<Photo> getPhoto(int id); Future<Photo> getPhoto(int id);
Future<List<Photo>> getAllPhotos({int? start, int? limit}); Future<List<Photo>> getAllPhotos({int? start, int? limit});
} }
@ -78,14 +78,31 @@ Several use cases are supported :
* Classic usecase : * Classic usecase :
```dart ```dart
class Test extends AsyncUseCase<QueryParameters, List<Photo>>> { class RetrieveAllAlbums extends AsyncUseCase<QueryParameters, List<Album>> {
const RetrieveAllAlbums(this._photoRepository);
final PhotoRepository _photoRepository;
@override @override
FuturOrResult<List<Photo>>> call(QueryParameters? params) { FutureOrResult<List<Album>> execute(QueryParameters params) {
final photos = _photoRepository.getAllPhotos( final albums = _photoRepository.getAllAlbums(
start: params.start, start: params.start,
limit: params.limit, limit: params.limit,
); );
return albums;
}
}
```
* No parameter usecase :
```dart
class DisplayFavorites extends NoParamsAsyncUseCase<List<Photo>> {
const DisplayFavorites(this._photoRepository);
final PhotoRepository _photoRepository;
@override
FutureOrResult<List<Photo>> execute() {
final photos = _photoRepository.getAllPhotosFromFavorites();
return photos; return photos;
} }
} }
@ -94,48 +111,51 @@ class Test extends AsyncUseCase<QueryParameters, List<Photo>>> {
You can add alternatve scenarios and check pre/post conditions using our extensions : You can add alternatve scenarios and check pre/post conditions using our extensions :
```dart ```dart
class SearchPhotos extends AsyncUseCase<QueryParameters, List<Photo>>> { class RetrieveAllAlbums extends AsyncUseCase<QueryParameters, List<Album>> {
const RetrieveAllAlbums(this._photoRepository);
final PhotoRepository _photoRepository;
@override @override
FutureOrResult<List<Photo>>> call(QueryParameters? params) { FutureOrResult<List<Album>> execute(QueryParameters params) {
final photos = _photoRepository.getAllPhotos( final albums = _photoRepository.getAllAlbums(
start: params.start, start: params.start,
limit: params.limit, limit: params.limit,
); );
return photos; return albums;
} }
@override @override
FutureOr<void> onStart(QueryParameters? params) { FutureOr<void> onStart(QueryParameters? params) {
if(params.start == null || params.limit == null){ if (params.start < 0) {
throw ClientException('Préconndition non valides'); throw const ClientException('Invalid start parameter');
} }
} }
} }
``` ```
You can implement error scenarios overriding `onError` , or check postconditions by overriding `onComplete` . You can implement error scenarios overriding `onException` , or check postconditions by overriding `onComplete` .
* Stream usecase : * Stream usecase :
```dart ```dart
class SearchPhotos extends StreamUseCase<QueryParameters, List<Photo>>> { class RetrieveAllAlbums extends AsyncUseCase<QueryParameters, List<Album>> {
const RetrieveAllAlbums(this._photoRepository);
final PhotoRepository _photoRepository;
@override @override
FutureOrResult<Stream<List<Photo>>>> call(QueryParameters? params) { FutureOrResult<List<Album>> execute(QueryParameters params) {
final photos = _photoRepository.getAllPhotos( final albums = _photoRepository.getAllAlbums(
start: params.start, start: params.start,
limit: params.limit, limit: params.limit,
); );
return photos; return albums;
} }
@override
FutureOrResult<List<Album>> onException(Object e) => Ok([]);
} }
``` ```
On this case, observers allow you to add alternative scenarios when data changed, overriding `onData` or `onDone` .
Please note that to use handlers, call `call` method and not `execute` . 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: