TF-4186 Add datasource/repository for save and get company server login info
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
import 'package:tmail_ui_user/features/login/domain/model/company_server_login_info.dart';
|
||||||
|
|
||||||
|
abstract class CompanyServerLoginDataSource {
|
||||||
|
Future<void> saveCompanyServerLoginInfo(CompanyServerLoginInfo loginInfo);
|
||||||
|
|
||||||
|
Future<CompanyServerLoginInfo> getCompanyServerLoginInfo();
|
||||||
|
|
||||||
|
Future<void> removeCompanyServerLoginInfo();
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import 'package:tmail_ui_user/features/login/data/datasource/company_server_login_datasource.dart';
|
||||||
|
import 'package:tmail_ui_user/features/login/data/local/company_server_login_cache_manager.dart';
|
||||||
|
import 'package:tmail_ui_user/features/login/domain/model/company_server_login_info.dart';
|
||||||
|
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
|
||||||
|
|
||||||
|
class CompanyServerLoginDatasourceImpl implements CompanyServerLoginDataSource {
|
||||||
|
final CompanyServerLoginCacheManager _loginCacheManager;
|
||||||
|
final ExceptionThrower _exceptionThrower;
|
||||||
|
|
||||||
|
CompanyServerLoginDatasourceImpl(
|
||||||
|
this._loginCacheManager,
|
||||||
|
this._exceptionThrower,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<CompanyServerLoginInfo> getCompanyServerLoginInfo() {
|
||||||
|
return Future.sync(() {
|
||||||
|
return _loginCacheManager.getCompanyServerLoginInfo();
|
||||||
|
}).catchError(_exceptionThrower.throwException);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> removeCompanyServerLoginInfo() {
|
||||||
|
return Future.sync(() async {
|
||||||
|
return await _loginCacheManager.removeCompanyServerLoginInfo();
|
||||||
|
}).catchError(_exceptionThrower.throwException);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> saveCompanyServerLoginInfo(CompanyServerLoginInfo loginInfo) {
|
||||||
|
return Future.sync(() async {
|
||||||
|
return await _loginCacheManager.saveCompanyServerLoginInfo(loginInfo);
|
||||||
|
}).catchError(_exceptionThrower.throwException);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:tmail_ui_user/features/login/domain/exceptions/login_exception.dart';
|
||||||
|
import 'package:tmail_ui_user/features/login/domain/model/company_server_login_info.dart';
|
||||||
|
|
||||||
|
class CompanyServerLoginCacheManager {
|
||||||
|
static const String _companyServerLoginInfoKey = 'COMPANY_SERVER_LOGIN_INFO';
|
||||||
|
|
||||||
|
const CompanyServerLoginCacheManager(this._sharedPreferences);
|
||||||
|
|
||||||
|
final SharedPreferences _sharedPreferences;
|
||||||
|
|
||||||
|
CompanyServerLoginInfo getCompanyServerLoginInfo() {
|
||||||
|
final userEmail = _sharedPreferences.getString(_companyServerLoginInfoKey);
|
||||||
|
if (userEmail?.trim().isNotEmpty == true) {
|
||||||
|
return CompanyServerLoginInfo(email: userEmail!);
|
||||||
|
} else {
|
||||||
|
throw NotFoundCompanyServerLoginInfoException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> saveCompanyServerLoginInfo(
|
||||||
|
CompanyServerLoginInfo companyServerLoginInfo,
|
||||||
|
) async {
|
||||||
|
await _sharedPreferences.setString(
|
||||||
|
_companyServerLoginInfoKey, companyServerLoginInfo.email);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> removeCompanyServerLoginInfo() async {
|
||||||
|
await _sharedPreferences.remove(_companyServerLoginInfoKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import 'package:tmail_ui_user/features/login/data/datasource/company_server_login_datasource.dart';
|
||||||
|
import 'package:tmail_ui_user/features/login/domain/model/company_server_login_info.dart';
|
||||||
|
import 'package:tmail_ui_user/features/login/domain/repository/company_server_login_repository.dart';
|
||||||
|
|
||||||
|
class CompanyServerLoginRepositoryImpl implements CompanyServerLoginRepository {
|
||||||
|
final CompanyServerLoginDataSource _serverLoginDataSource;
|
||||||
|
|
||||||
|
CompanyServerLoginRepositoryImpl(this._serverLoginDataSource);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<CompanyServerLoginInfo> getCompanyServerLoginInfo() {
|
||||||
|
return _serverLoginDataSource.getCompanyServerLoginInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> removeCompanyServerLoginInfo() {
|
||||||
|
return _serverLoginDataSource.removeCompanyServerLoginInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> saveCompanyServerLoginInfo(CompanyServerLoginInfo loginInfo) {
|
||||||
|
return _serverLoginDataSource.saveCompanyServerLoginInfo(loginInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,3 +21,5 @@ class NoSuitableBrowserForOIDCException implements Exception {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class NotFoundCompanyServerLoginInfoException implements Exception {}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
|
||||||
|
class CompanyServerLoginInfo with EquatableMixin {
|
||||||
|
final String email;
|
||||||
|
|
||||||
|
const CompanyServerLoginInfo({
|
||||||
|
required this.email,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [email];
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import 'package:tmail_ui_user/features/login/domain/model/company_server_login_info.dart';
|
||||||
|
|
||||||
|
abstract class CompanyServerLoginRepository {
|
||||||
|
Future<void> saveCompanyServerLoginInfo(CompanyServerLoginInfo loginInfo);
|
||||||
|
|
||||||
|
Future<CompanyServerLoginInfo> getCompanyServerLoginInfo();
|
||||||
|
|
||||||
|
Future<void> removeCompanyServerLoginInfo();
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import 'package:core/presentation/state/failure.dart';
|
||||||
|
import 'package:core/presentation/state/success.dart';
|
||||||
|
import 'package:tmail_ui_user/features/login/domain/model/company_server_login_info.dart';
|
||||||
|
|
||||||
|
class GettingCompanyServerLoginInfo extends LoadingState {}
|
||||||
|
|
||||||
|
class GetCompanyServerLoginInfoSuccess extends UIState {
|
||||||
|
final CompanyServerLoginInfo serverLoginInfo;
|
||||||
|
|
||||||
|
GetCompanyServerLoginInfoSuccess(this.serverLoginInfo);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [serverLoginInfo];
|
||||||
|
}
|
||||||
|
|
||||||
|
class GetCompanyServerLoginInfoFailure extends FeatureFailure {
|
||||||
|
GetCompanyServerLoginInfoFailure(dynamic exception)
|
||||||
|
: super(exception: exception);
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import 'package:core/presentation/state/failure.dart';
|
||||||
|
import 'package:core/presentation/state/success.dart';
|
||||||
|
|
||||||
|
class SavingCompanyServerLoginInfo extends LoadingState {}
|
||||||
|
|
||||||
|
class SaveCompanyServerLoginInfoSuccess extends UIState {}
|
||||||
|
|
||||||
|
class SaveCompanyServerLoginInfoFailure extends FeatureFailure {
|
||||||
|
SaveCompanyServerLoginInfoFailure(dynamic exception)
|
||||||
|
: super(exception: exception);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import 'dart:core';
|
||||||
|
|
||||||
|
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/login/domain/repository/company_server_login_repository.dart';
|
||||||
|
import 'package:tmail_ui_user/features/login/domain/state/get_company_server_login_info_state.dart';
|
||||||
|
|
||||||
|
class GetCompanyServerLoginInfoInteractor {
|
||||||
|
final CompanyServerLoginRepository _serverLoginRepository;
|
||||||
|
|
||||||
|
GetCompanyServerLoginInfoInteractor(this._serverLoginRepository);
|
||||||
|
|
||||||
|
Stream<Either<Failure, Success>> execute() async* {
|
||||||
|
try {
|
||||||
|
yield Right(GettingCompanyServerLoginInfo());
|
||||||
|
final serverLoginInfo =
|
||||||
|
await _serverLoginRepository.getCompanyServerLoginInfo();
|
||||||
|
yield Right(GetCompanyServerLoginInfoSuccess(serverLoginInfo));
|
||||||
|
} catch (exception) {
|
||||||
|
yield Left(GetCompanyServerLoginInfoFailure(exception));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import 'dart:core';
|
||||||
|
|
||||||
|
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/login/domain/model/company_server_login_info.dart';
|
||||||
|
import 'package:tmail_ui_user/features/login/domain/repository/company_server_login_repository.dart';
|
||||||
|
import 'package:tmail_ui_user/features/login/domain/state/save_company_server_login_info_state.dart';
|
||||||
|
|
||||||
|
class SaveCompanyServerLoginInfoInteractor {
|
||||||
|
final CompanyServerLoginRepository _serverLoginRepository;
|
||||||
|
|
||||||
|
SaveCompanyServerLoginInfoInteractor(this._serverLoginRepository);
|
||||||
|
|
||||||
|
Stream<Either<Failure, Success>> execute(
|
||||||
|
CompanyServerLoginInfo serverLoginInfo,
|
||||||
|
) async* {
|
||||||
|
try {
|
||||||
|
yield Right(SavingCompanyServerLoginInfo());
|
||||||
|
await _serverLoginRepository.saveCompanyServerLoginInfo(serverLoginInfo);
|
||||||
|
yield Right(SaveCompanyServerLoginInfoSuccess());
|
||||||
|
} catch (exception) {
|
||||||
|
yield Left(SaveCompanyServerLoginInfoFailure(exception));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user