milestone/stable-1-reconcile-auth-3 #176
@ -23,7 +23,7 @@
 | 
			
		||||
  <img src="https://img.shields.io/badge/SDK-Flutter-blue?style=flat-square" alt="SDK: Flutter" />
 | 
			
		||||
</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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -36,7 +36,7 @@ class PhotoRepositoryImpl extends PhotoRepository {
 | 
			
		||||
  @override
 | 
			
		||||
  FutureOrResult<void> addPhotoToFavorites(Photo photo) => Result.tryCatchAsync(
 | 
			
		||||
        () => _favoriteLocalDataSource.addPhotoToFavorites(photo),
 | 
			
		||||
        (error) => ClientException('Cannot add photo to favorites.'),
 | 
			
		||||
        (error) => const ClientException('Cannot add photo to favorites.'),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
@ -63,14 +63,14 @@ class PhotoRepositoryImpl extends PhotoRepository {
 | 
			
		||||
  FutureOrResult<List<Album>> getAllAlbums({int? start, int? limit}) =>
 | 
			
		||||
      Result.tryCatchAsync(
 | 
			
		||||
        () => _albumRemoteDataSource.getAllAlbums(start: start, limit: limit),
 | 
			
		||||
        (error) => ServerException('Cannot retrieve all albums.'),
 | 
			
		||||
        (error) => const ServerException('Cannot retrieve all albums.'),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  FutureOrResult<List<Photo>> getAllPhotos({int? start, int? limit}) async =>
 | 
			
		||||
      Result.tryCatchAsync(
 | 
			
		||||
        () => _photoRemoteDataSource.getAllPhotos(start: start, limit: limit),
 | 
			
		||||
        (error) => ServerException('Cannot retrieve all photos.'),
 | 
			
		||||
        (error) => const ServerException('Cannot retrieve all photos.'),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
@ -88,7 +88,7 @@ class PhotoRepositoryImpl extends PhotoRepository {
 | 
			
		||||
      }
 | 
			
		||||
      return Ok(response);
 | 
			
		||||
    } catch (_) {
 | 
			
		||||
      return Err(
 | 
			
		||||
      return const Err(
 | 
			
		||||
        ClientException('Cannot retrieve all photos from favorites.'),
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -33,7 +33,7 @@ class AddPhotoToFavorites extends AsyncUseCase<Photo, List<Photo>> {
 | 
			
		||||
  @override
 | 
			
		||||
  FutureOr<void> onStart(Photo? params) {
 | 
			
		||||
    if (params == null) {
 | 
			
		||||
      throw ClientException('Photo cannot be null');
 | 
			
		||||
      throw const ClientException('Photo cannot be null');
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -30,7 +30,7 @@ class CheckIfPhotoIsInFavorites extends AsyncUseCase<int, bool> {
 | 
			
		||||
  @override
 | 
			
		||||
  FutureOr<void> onStart(int? params) {
 | 
			
		||||
    if (params == null) {
 | 
			
		||||
      throw ClientException('id cannot be null');
 | 
			
		||||
      throw const ClientException('id cannot be null');
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -33,7 +33,7 @@ class DisplayPhoto extends AsyncUseCase<int, Photo> {
 | 
			
		||||
  @override
 | 
			
		||||
  FutureOr<void> onStart(int? params) {
 | 
			
		||||
    if (params == null) {
 | 
			
		||||
      throw ClientException('id cannot be null');
 | 
			
		||||
      throw const ClientException('id cannot be null');
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -39,7 +39,7 @@ class OpenAlbum extends AsyncUseCase<QueryParameters, List<Photo>> {
 | 
			
		||||
  @override
 | 
			
		||||
  FutureOr<void> onStart(QueryParameters? params) {
 | 
			
		||||
    if (params == null) {
 | 
			
		||||
      throw ClientException('params cannot be null');
 | 
			
		||||
      throw const ClientException('params cannot be null');
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -33,7 +33,7 @@ class RemovePhotoFromFavorites extends AsyncUseCase<int, List<Photo>> {
 | 
			
		||||
  @override
 | 
			
		||||
  FutureOr<void> onStart(int? params) {
 | 
			
		||||
    if (params == null) {
 | 
			
		||||
      throw ClientException('id cannot be null');
 | 
			
		||||
      throw const ClientException('id cannot be null');
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -37,7 +37,7 @@ class RetrieveAllAlbums extends AsyncUseCase<QueryParameters, List<Album>> {
 | 
			
		||||
  @override
 | 
			
		||||
  FutureOr<void> onStart(QueryParameters? params) {
 | 
			
		||||
    if (params == null) {
 | 
			
		||||
      throw ClientException('params cannot be null');
 | 
			
		||||
      throw const ClientException('params cannot be null');
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -16,8 +16,13 @@
 | 
			
		||||
 | 
			
		||||
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 {
 | 
			
		||||
  AppException([this.message]);
 | 
			
		||||
  /// {@macro app_exception}
 | 
			
		||||
  const AppException([this.message]);
 | 
			
		||||
 | 
			
		||||
  final String? message;
 | 
			
		||||
 | 
			
		||||
  @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 {
 | 
			
		||||
  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 {
 | 
			
		||||
  ServerException([super.message]);
 | 
			
		||||
  /// {@macro server_exception}
 | 
			
		||||
  const ServerException([super.message]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -14,6 +14,11 @@
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// 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 {
 | 
			
		||||
  /// {@macro base_data_source}
 | 
			
		||||
  const BaseDataSource();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -16,6 +16,11 @@
 | 
			
		||||
 | 
			
		||||
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 {
 | 
			
		||||
  /// {@macro base_local_data_source}
 | 
			
		||||
  const BaseLocalDataSource();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -16,6 +16,11 @@
 | 
			
		||||
 | 
			
		||||
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 {
 | 
			
		||||
  /// {@macro base_remote_data_source}
 | 
			
		||||
  const BaseRemoteDataSource();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -14,6 +14,10 @@
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// 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 {
 | 
			
		||||
  /// {@macro entity}
 | 
			
		||||
  const Entity();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -14,6 +14,10 @@
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// 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 {
 | 
			
		||||
  /// {@macro base_repository}
 | 
			
		||||
  const BaseRepository();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -16,6 +16,11 @@
 | 
			
		||||
 | 
			
		||||
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 {
 | 
			
		||||
  /// {@macro no_param}
 | 
			
		||||
  const NoParam();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,16 +21,17 @@ import 'package:wyatt_architecture/wyatt_architecture.dart';
 | 
			
		||||
/// Usecase observers
 | 
			
		||||
mixin Observer<Parameters, ReturnType> {
 | 
			
		||||
  /// Called before usecase is runned.
 | 
			
		||||
  /// Usefull to check the preconditions
 | 
			
		||||
  /// Useful to check the preconditions
 | 
			
		||||
  FutureOr<void> onStart(Parameters? params) {}
 | 
			
		||||
 | 
			
		||||
  /// Called when error occures during main scenario
 | 
			
		||||
  /// Usefull to run alternative scenario
 | 
			
		||||
  /// Useful to run alternative scenario
 | 
			
		||||
  FutureOr<void> onError(AppException? error) {}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Specific observer for classic usecase
 | 
			
		||||
mixin AsyncObserver<ReturnType> {
 | 
			
		||||
  /// Called when usecase is completed
 | 
			
		||||
  FutureOr<void> onComplete(ReturnType? data) {}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -39,6 +40,6 @@ mixin StreamObserver<ReturnType> {
 | 
			
		||||
  /// Replaces the data event handler of this subscription.
 | 
			
		||||
  void onDone() {}
 | 
			
		||||
 | 
			
		||||
  ///  Replaces the done event handler of this subscription.
 | 
			
		||||
  /// Replaces the done event handler of this subscription.
 | 
			
		||||
  void onData(ReturnType? data) {}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -23,8 +23,13 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart';
 | 
			
		||||
typedef FutureOrResult<T> = FutureOr<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> {
 | 
			
		||||
  /// {@macro base_usecase}
 | 
			
		||||
  const BaseUseCase();
 | 
			
		||||
 | 
			
		||||
  /// Run use case scenarios
 | 
			
		||||
  ReturnType call(Parameters parameters);
 | 
			
		||||
 | 
			
		||||
@ -33,11 +38,16 @@ abstract class BaseUseCase<Parameters, ReturnType> {
 | 
			
		||||
  ReturnType execute(Parameters params);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// {@template usecase}
 | 
			
		||||
/// Abstract class of a use case that deals specifically
 | 
			
		||||
/// with the response and its state.
 | 
			
		||||
/// {@endtemplate}
 | 
			
		||||
abstract class UseCase<Parameters, ReturnType>
 | 
			
		||||
    extends BaseUseCase<Parameters?, FutureOrResult<ReturnType>>
 | 
			
		||||
    with Observer<Parameters, ReturnType> {
 | 
			
		||||
  /// {@macro usecase}
 | 
			
		||||
  const UseCase();
 | 
			
		||||
 | 
			
		||||
  FutureOr<void> _onSuccess(ReturnType data);
 | 
			
		||||
 | 
			
		||||
  /// 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>
 | 
			
		||||
    extends UseCase<Parameters?, ReturnType> with AsyncObserver<ReturnType> {
 | 
			
		||||
  /// {@macro async_usecase}
 | 
			
		||||
  const AsyncUseCase();
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  FutureOr<void> _onSuccess(ReturnType data) => onComplete(data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// {@template stream_usecase}
 | 
			
		||||
/// Abstract specific usecase bases on streams
 | 
			
		||||
/// {@endtemplate}
 | 
			
		||||
abstract class StreamUseCase<Parameters, ReturnType>
 | 
			
		||||
    extends UseCase<Parameters?, Stream<ReturnType>>
 | 
			
		||||
    with StreamObserver<ReturnType> {
 | 
			
		||||
  /// {@macro stream_usecase}
 | 
			
		||||
  const StreamUseCase();
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  FutureOr<void> _onSuccess(Stream<ReturnType> data) {
 | 
			
		||||
    data.listen(
 | 
			
		||||
 | 
			
		||||
@ -14,7 +14,7 @@
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
/// Architecture
 | 
			
		||||
/// Wyatt Architecture for Flutter
 | 
			
		||||
library wyatt_architecture;
 | 
			
		||||
 | 
			
		||||
export 'src/src.dart';
 | 
			
		||||
 | 
			
		||||
@ -1,27 +1,23 @@
 | 
			
		||||
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
 | 
			
		||||
version: 0.1.0+1
 | 
			
		||||
 | 
			
		||||
publish_to: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub
 | 
			
		||||
 | 
			
		||||
environment:
 | 
			
		||||
  sdk: '>=2.17.0 <3.0.0'
 | 
			
		||||
  sdk: ">=2.17.0 <3.0.0"
 | 
			
		||||
 | 
			
		||||
dependencies:
 | 
			
		||||
  
 | 
			
		||||
  flutter:
 | 
			
		||||
    sdk: flutter
 | 
			
		||||
  flutter: { sdk: flutter }
 | 
			
		||||
 | 
			
		||||
  wyatt_type_utils:
 | 
			
		||||
    hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub
 | 
			
		||||
    version: ^0.0.4
 | 
			
		||||
 | 
			
		||||
dev_dependencies:
 | 
			
		||||
  
 | 
			
		||||
  flutter_test:
 | 
			
		||||
    sdk: flutter
 | 
			
		||||
  
 | 
			
		||||
  flutter_test: { sdk: flutter }
 | 
			
		||||
 | 
			
		||||
  wyatt_analysis:
 | 
			
		||||
    hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub
 | 
			
		||||
    version: ^2.4.1
 | 
			
		||||
    version: ^2.4.1
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user