master #81

Closed
malo wants to merge 322 commits from master into feat/bloc_layout/new-package
19 changed files with 90 additions and 30 deletions
Showing only changes of commit e5e0550017 - Show all commits

View File

@ -23,7 +23,7 @@
<img src="https://img.shields.io/badge/SDK-Flutter-blue?style=flat-square" alt="SDK: Flutter" /> <img src="https://img.shields.io/badge/SDK-Flutter-blue?style=flat-square" alt="SDK: Flutter" />
</p> </p>
The Wyatt Architecture for Flutter. The Wyatt Architecture for Flutter. Contains useful classes to help you to create a clean architecture following the Wyatt Architecture. (core, data, domain, presentation).
## Features ## Features

View File

@ -36,7 +36,7 @@ class PhotoRepositoryImpl extends PhotoRepository {
@override @override
FutureOrResult<void> addPhotoToFavorites(Photo photo) => Result.tryCatchAsync( FutureOrResult<void> addPhotoToFavorites(Photo photo) => Result.tryCatchAsync(
() => _favoriteLocalDataSource.addPhotoToFavorites(photo), () => _favoriteLocalDataSource.addPhotoToFavorites(photo),
(error) => ClientException('Cannot add photo to favorites.'), (error) => const ClientException('Cannot add photo to favorites.'),
); );
@override @override
@ -63,14 +63,14 @@ class PhotoRepositoryImpl extends PhotoRepository {
FutureOrResult<List<Album>> getAllAlbums({int? start, int? limit}) => FutureOrResult<List<Album>> getAllAlbums({int? start, int? limit}) =>
Result.tryCatchAsync( Result.tryCatchAsync(
() => _albumRemoteDataSource.getAllAlbums(start: start, limit: limit), () => _albumRemoteDataSource.getAllAlbums(start: start, limit: limit),
(error) => ServerException('Cannot retrieve all albums.'), (error) => const ServerException('Cannot retrieve all albums.'),
); );
@override @override
FutureOrResult<List<Photo>> getAllPhotos({int? start, int? limit}) async => FutureOrResult<List<Photo>> getAllPhotos({int? start, int? limit}) async =>
Result.tryCatchAsync( Result.tryCatchAsync(
() => _photoRemoteDataSource.getAllPhotos(start: start, limit: limit), () => _photoRemoteDataSource.getAllPhotos(start: start, limit: limit),
(error) => ServerException('Cannot retrieve all photos.'), (error) => const ServerException('Cannot retrieve all photos.'),
); );
@override @override
@ -88,7 +88,7 @@ class PhotoRepositoryImpl extends PhotoRepository {
} }
return Ok(response); return Ok(response);
} catch (_) { } catch (_) {
return Err( return const Err(
ClientException('Cannot retrieve all photos from favorites.'), ClientException('Cannot retrieve all photos from favorites.'),
); );
} }

View File

@ -33,7 +33,7 @@ class AddPhotoToFavorites extends AsyncUseCase<Photo, List<Photo>> {
@override @override
FutureOr<void> onStart(Photo? params) { FutureOr<void> onStart(Photo? params) {
if (params == null) { if (params == null) {
throw ClientException('Photo cannot be null'); throw const ClientException('Photo cannot be null');
} }
} }
} }

View File

@ -30,7 +30,7 @@ class CheckIfPhotoIsInFavorites extends AsyncUseCase<int, bool> {
@override @override
FutureOr<void> onStart(int? params) { FutureOr<void> onStart(int? params) {
if (params == null) { if (params == null) {
throw ClientException('id cannot be null'); throw const ClientException('id cannot be null');
} }
} }
} }

View File

@ -33,7 +33,7 @@ class DisplayPhoto extends AsyncUseCase<int, Photo> {
@override @override
FutureOr<void> onStart(int? params) { FutureOr<void> onStart(int? params) {
if (params == null) { if (params == null) {
throw ClientException('id cannot be null'); throw const ClientException('id cannot be null');
} }
} }
} }

View File

@ -39,7 +39,7 @@ class OpenAlbum extends AsyncUseCase<QueryParameters, List<Photo>> {
@override @override
FutureOr<void> onStart(QueryParameters? params) { FutureOr<void> onStart(QueryParameters? params) {
if (params == null) { if (params == null) {
throw ClientException('params cannot be null'); throw const ClientException('params cannot be null');
} }
} }
} }

View File

@ -33,7 +33,7 @@ class RemovePhotoFromFavorites extends AsyncUseCase<int, List<Photo>> {
@override @override
FutureOr<void> onStart(int? params) { FutureOr<void> onStart(int? params) {
if (params == null) { if (params == null) {
throw ClientException('id cannot be null'); throw const ClientException('id cannot be null');
} }
} }
} }

View File

@ -37,7 +37,7 @@ class RetrieveAllAlbums extends AsyncUseCase<QueryParameters, List<Album>> {
@override @override
FutureOr<void> onStart(QueryParameters? params) { FutureOr<void> onStart(QueryParameters? params) {
if (params == null) { if (params == null) {
throw ClientException('params cannot be null'); throw const ClientException('params cannot be null');
} }
} }
} }

View File

@ -16,8 +16,13 @@
import 'package:wyatt_type_utils/wyatt_type_utils.dart'; import 'package:wyatt_type_utils/wyatt_type_utils.dart';
/// {@template app_exception}
/// [AppException] is a base class for all exceptions in the wyatt architecture.
/// {@endtemplate}
abstract class AppException implements Exception { abstract class AppException implements Exception {
AppException([this.message]); /// {@macro app_exception}
const AppException([this.message]);
final String? message; final String? message;
@override @override
@ -30,10 +35,20 @@ abstract class AppException implements Exception {
} }
} }
/// {@template client_exception}
/// [ClientException] is a base class for all client exceptions in the wyatt
/// architecture.
/// {@endtemplate}
class ClientException extends AppException { class ClientException extends AppException {
ClientException([super.message]); /// {@macro client_exception}
const ClientException([super.message]);
} }
/// {@template server_exception}
/// [ServerException] is a base class for all server exceptions in the wyatt
/// architecture.
/// {@endtemplate}
class ServerException extends AppException { class ServerException extends AppException {
ServerException([super.message]); /// {@macro server_exception}
const ServerException([super.message]);
} }

View File

@ -14,6 +14,11 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
/// {@template base_data_source}
/// [BaseDataSource] is a base class for all data sources in the wyatt
/// architecture.
/// {@endtemplate}
abstract class BaseDataSource { abstract class BaseDataSource {
/// {@macro base_data_source}
const BaseDataSource(); const BaseDataSource();
} }

View File

@ -16,6 +16,11 @@
import 'package:wyatt_architecture/src/domain/data_sources/base_data_source.dart'; import 'package:wyatt_architecture/src/domain/data_sources/base_data_source.dart';
/// {@template base_local_data_source}
/// [BaseLocalDataSource] is a base class for all local data sources in the
/// wyatt architecture.
/// {@endtemplate}
abstract class BaseLocalDataSource extends BaseDataSource { abstract class BaseLocalDataSource extends BaseDataSource {
/// {@macro base_local_data_source}
const BaseLocalDataSource(); const BaseLocalDataSource();
} }

View File

@ -16,6 +16,11 @@
import 'package:wyatt_architecture/src/domain/data_sources/base_data_source.dart'; import 'package:wyatt_architecture/src/domain/data_sources/base_data_source.dart';
/// {@template base_remote_data_source}
/// [BaseRemoteDataSource] is a base class for all remote data sources in the
/// wyatt architecture.
/// {@endtemplate}
abstract class BaseRemoteDataSource extends BaseDataSource { abstract class BaseRemoteDataSource extends BaseDataSource {
/// {@macro base_remote_data_source}
const BaseRemoteDataSource(); const BaseRemoteDataSource();
} }

View File

@ -14,6 +14,10 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
/// {@template entity}
/// [Entity] is a base class for all entities in the domain layer.
/// {@endtemplate}
abstract class Entity { abstract class Entity {
/// {@macro entity}
const Entity(); const Entity();
} }

View File

@ -14,6 +14,10 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
/// {@template base_repository}
/// [BaseRepository] is a base class for all repositories in the domain layer.
/// {@endtemplate}
abstract class BaseRepository { abstract class BaseRepository {
/// {@macro base_repository}
const BaseRepository(); const BaseRepository();
} }

View File

@ -16,6 +16,11 @@
import 'package:wyatt_architecture/src/domain/entities/entity.dart'; import 'package:wyatt_architecture/src/domain/entities/entity.dart';
/// {@template no_param}
/// [NoParam] is a class that is used when a use case does not require any
/// parameters.
/// {@endtemplate}
class NoParam extends Entity { class NoParam extends Entity {
/// {@macro no_param}
const NoParam(); const NoParam();
} }

View File

@ -21,16 +21,17 @@ import 'package:wyatt_architecture/wyatt_architecture.dart';
/// Usecase observers /// Usecase observers
mixin Observer<Parameters, ReturnType> { mixin Observer<Parameters, ReturnType> {
/// Called before usecase is runned. /// Called before usecase is runned.
/// Usefull to check the preconditions /// Useful to check the preconditions
FutureOr<void> onStart(Parameters? params) {} FutureOr<void> onStart(Parameters? params) {}
/// Called when error occures during main scenario /// Called when error occures during main scenario
/// Usefull to run alternative scenario /// Useful to run alternative scenario
FutureOr<void> onError(AppException? error) {} FutureOr<void> onError(AppException? error) {}
} }
/// Specific observer for classic usecase /// Specific observer for classic usecase
mixin AsyncObserver<ReturnType> { mixin AsyncObserver<ReturnType> {
/// Called when usecase is completed
FutureOr<void> onComplete(ReturnType? data) {} FutureOr<void> onComplete(ReturnType? data) {}
} }

View File

@ -23,8 +23,13 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart';
typedef FutureOrResult<T> = FutureOr<Result<T, AppException>>; typedef FutureOrResult<T> = FutureOr<Result<T, AppException>>;
typedef StreamResult<T> = Stream<Result<T, AppException>>; typedef StreamResult<T> = Stream<Result<T, AppException>>;
/// Abstract class of a use case /// {@template base_usecase}
/// Abstract class of any use case.
/// {@endtemplate}
abstract class BaseUseCase<Parameters, ReturnType> { abstract class BaseUseCase<Parameters, ReturnType> {
/// {@macro base_usecase}
const BaseUseCase();
/// Run use case scenarios /// Run use case scenarios
ReturnType call(Parameters parameters); ReturnType call(Parameters parameters);
@ -33,11 +38,16 @@ abstract class BaseUseCase<Parameters, ReturnType> {
ReturnType execute(Parameters params); ReturnType execute(Parameters params);
} }
/// {@template usecase}
/// Abstract class of a use case that deals specifically /// Abstract class of a use case that deals specifically
/// with the response and its state. /// with the response and its state.
/// {@endtemplate}
abstract class UseCase<Parameters, ReturnType> abstract class UseCase<Parameters, ReturnType>
extends BaseUseCase<Parameters?, FutureOrResult<ReturnType>> extends BaseUseCase<Parameters?, FutureOrResult<ReturnType>>
with Observer<Parameters, ReturnType> { with Observer<Parameters, ReturnType> {
/// {@macro usecase}
const UseCase();
FutureOr<void> _onSuccess(ReturnType data); FutureOr<void> _onSuccess(ReturnType data);
/// Supports the result of the main scenario and integrates /// Supports the result of the main scenario and integrates
@ -59,17 +69,27 @@ abstract class UseCase<Parameters, ReturnType>
} }
} }
/// Abtstract classic usecase. /// {@template async_usecase}
/// Abtstract classic usecase bases on futures
/// {@endtemplate}
abstract class AsyncUseCase<Parameters, ReturnType> abstract class AsyncUseCase<Parameters, ReturnType>
extends UseCase<Parameters?, ReturnType> with AsyncObserver<ReturnType> { extends UseCase<Parameters?, ReturnType> with AsyncObserver<ReturnType> {
/// {@macro async_usecase}
const AsyncUseCase();
@override @override
FutureOr<void> _onSuccess(ReturnType data) => onComplete(data); FutureOr<void> _onSuccess(ReturnType data) => onComplete(data);
} }
/// {@template stream_usecase}
/// Abstract specific usecase bases on streams /// Abstract specific usecase bases on streams
/// {@endtemplate}
abstract class StreamUseCase<Parameters, ReturnType> abstract class StreamUseCase<Parameters, ReturnType>
extends UseCase<Parameters?, Stream<ReturnType>> extends UseCase<Parameters?, Stream<ReturnType>>
with StreamObserver<ReturnType> { with StreamObserver<ReturnType> {
/// {@macro stream_usecase}
const StreamUseCase();
@override @override
FutureOr<void> _onSuccess(Stream<ReturnType> data) { FutureOr<void> _onSuccess(Stream<ReturnType> data) {
data.listen( data.listen(

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
/// Architecture /// Wyatt Architecture for Flutter
library wyatt_architecture; library wyatt_architecture;
export 'src/src.dart'; export 'src/src.dart';

View File

@ -1,26 +1,22 @@
name: wyatt_architecture name: wyatt_architecture
description: A new Wyatt package description: Wyatt Architecture contains useful classes to help you to create a clean architecture following the Wyatt Architecture principles.
repository: https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/wyatt_architecture repository: https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/wyatt_architecture
version: 0.1.0+1 version: 0.1.0+1
publish_to: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub publish_to: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub
environment: environment:
sdk: '>=2.17.0 <3.0.0' sdk: ">=2.17.0 <3.0.0"
dependencies: dependencies:
flutter: { sdk: flutter }
flutter:
sdk: flutter
wyatt_type_utils: wyatt_type_utils:
hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub
version: ^0.0.4 version: ^0.0.4
dev_dependencies: dev_dependencies:
flutter_test: { sdk: flutter }
flutter_test:
sdk: flutter
wyatt_analysis: wyatt_analysis:
hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub