TF-1899 Implement interactor for get stored session
(cherry picked from commit 05eb5a5b9da2ab3fba64ea08591fd787a736549e)
This commit is contained in:
@@ -4,4 +4,6 @@ abstract class SessionRepository {
|
||||
Future<Session> getSession();
|
||||
|
||||
Future<void> storeSession(Session session);
|
||||
|
||||
Future<Session> getStoredSession();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
|
||||
class GetStoredSessionLoading extends UIState {}
|
||||
|
||||
class GetStoredSessionSuccess extends UIState {
|
||||
|
||||
final Session session;
|
||||
|
||||
GetStoredSessionSuccess(this.session);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [session];
|
||||
}
|
||||
|
||||
class GetStoredSessionFailure extends FeatureFailure {
|
||||
|
||||
GetStoredSessionFailure(dynamic exception) : super(exception: exception);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [exception];
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:tmail_ui_user/features/session/domain/repository/session_repository.dart';
|
||||
import 'package:tmail_ui_user/features/session/domain/state/get_stored_session_state.dart';
|
||||
|
||||
class GetStoredSessionInteractor {
|
||||
final SessionRepository sessionRepository;
|
||||
|
||||
GetStoredSessionInteractor(this.sessionRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute() async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(GetStoredSessionLoading());
|
||||
final session = await sessionRepository.getStoredSession();
|
||||
yield Right<Failure, Success>(GetStoredSessionSuccess(session));
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(GetStoredSessionFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user