TF-1899 Implement interactor for get stored session
(cherry picked from commit 05eb5a5b9da2ab3fba64ea08591fd787a736549e)
This commit is contained in:
@@ -4,4 +4,6 @@ abstract class SessionDataSource {
|
|||||||
Future<Session> getSession();
|
Future<Session> getSession();
|
||||||
|
|
||||||
Future<void> storeSession(Session session);
|
Future<void> storeSession(Session session);
|
||||||
|
|
||||||
|
Future<Session> getStoredSession();
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/clients/session_hive_cache_client.dart';
|
import 'package:tmail_ui_user/features/caching/clients/session_hive_cache_client.dart';
|
||||||
import 'package:tmail_ui_user/features/session/data/datasource/session_datasource.dart';
|
import 'package:tmail_ui_user/features/session/data/datasource/session_datasource.dart';
|
||||||
|
import 'package:tmail_ui_user/features/session/data/exceptions/session_exceptions.dart';
|
||||||
|
import 'package:tmail_ui_user/features/session/data/extensions/session_hive_obj_extension.dart';
|
||||||
import 'package:tmail_ui_user/features/session/data/model/session_hive_obj.dart';
|
import 'package:tmail_ui_user/features/session/data/model/session_hive_obj.dart';
|
||||||
import 'package:tmail_ui_user/features/session/domain/extensions/session_extensions.dart';
|
import 'package:tmail_ui_user/features/session/domain/extensions/session_extensions.dart';
|
||||||
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
|
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
|
||||||
@@ -23,4 +25,16 @@ class HiveSessionDataSourceImpl extends SessionDataSource {
|
|||||||
return _sessionHiveCacheClient.insertItem(SessionHiveObj.keyValue, session.toHiveObj());
|
return _sessionHiveCacheClient.insertItem(SessionHiveObj.keyValue, session.toHiveObj());
|
||||||
}).catchError(_exceptionThrower.throwException);
|
}).catchError(_exceptionThrower.throwException);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Session> getStoredSession() {
|
||||||
|
return Future.sync(() async {
|
||||||
|
final sessionHiveObj = await _sessionHiveCacheClient.getItem(SessionHiveObj.keyValue);
|
||||||
|
if (sessionHiveObj != null) {
|
||||||
|
return sessionHiveObj.toSession();
|
||||||
|
} else {
|
||||||
|
throw NotFoundSessionHiveObject();
|
||||||
|
}
|
||||||
|
}).catchError(_exceptionThrower.throwException);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -21,4 +21,9 @@ class SessionDataSourceImpl extends SessionDataSource {
|
|||||||
Future<void> storeSession(Session session) {
|
Future<void> storeSession(Session session) {
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Session> getStoredSession() {
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -18,4 +18,9 @@ class SessionRepositoryImpl extends SessionRepository {
|
|||||||
Future<void> storeSession(Session session) {
|
Future<void> storeSession(Session session) {
|
||||||
return sessionDataSource[DataSourceType.hiveCache]!.storeSession(session);
|
return sessionDataSource[DataSourceType.hiveCache]!.storeSession(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Session> getStoredSession() {
|
||||||
|
return sessionDataSource[DataSourceType.hiveCache]!.getStoredSession();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,4 +4,6 @@ abstract class SessionRepository {
|
|||||||
Future<Session> getSession();
|
Future<Session> getSession();
|
||||||
|
|
||||||
Future<void> storeSession(Session session);
|
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