TF-1068 implement data layer save recent login username & get all login username
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
class RecentLoginUsername with EquatableMixin {
|
||||
final String username;
|
||||
final DateTime creationDate;
|
||||
|
||||
RecentLoginUsername(this.username, this.creationDate);
|
||||
|
||||
factory RecentLoginUsername.now(String username) => RecentLoginUsername(username, DateTime.now());
|
||||
|
||||
@override
|
||||
List<Object?> get props => [ username, creationDate ];
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/model/recent_login_username.dart';
|
||||
|
||||
class GetAllRecentLoginUsernameLatestSuccess extends UIState {
|
||||
|
||||
final List<RecentLoginUsername> listRecentLoginUsername;
|
||||
|
||||
GetAllRecentLoginUsernameLatestSuccess(this.listRecentLoginUsername);
|
||||
|
||||
@override
|
||||
List<Object> get props => [listRecentLoginUsername];
|
||||
}
|
||||
|
||||
class GetAllRecentLoginUsernameLatestFailure extends FeatureFailure {
|
||||
final dynamic exception;
|
||||
|
||||
GetAllRecentLoginUsernameLatestFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object> get props => [exception];
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
|
||||
class SaveRecentLoginUsernameSuccess extends UIState {
|
||||
|
||||
SaveRecentLoginUsernameSuccess();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class SaveRecentLoginUsernameFailed extends FeatureFailure {
|
||||
final dynamic exception;
|
||||
|
||||
SaveRecentLoginUsernameFailed(this.exception);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [exception];
|
||||
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/login_username_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/state/get_all_recent_login_username_state.dart';
|
||||
|
||||
class GetAllRecentLoginUsernameOnMobileInteractor {
|
||||
final LoginUsernameRepository loginUsernameRepository;
|
||||
|
||||
GetAllRecentLoginUsernameOnMobileInteractor(this.loginUsernameRepository);
|
||||
|
||||
Future<Either<Failure, Success>> execute({int? limit, String? pattern}) async {
|
||||
try {
|
||||
final listRecent = await loginUsernameRepository.getAllRecentLoginUsernameLatest(
|
||||
limit: limit, pattern: pattern);
|
||||
return Right(GetAllRecentLoginUsernameLatestSuccess(listRecent));
|
||||
} catch (exception) {
|
||||
return Left(GetAllRecentLoginUsernameLatestFailure(exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/model/recent_login_username.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/login_username_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/state/save_recent_login_username_state.dart';
|
||||
|
||||
class SaveLoginUsernameOnMobileInteractor {
|
||||
final LoginUsernameRepository loginUsernameRepository;
|
||||
|
||||
SaveLoginUsernameOnMobileInteractor(this.loginUsernameRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(RecentLoginUsername recentLoginUsername) async* {
|
||||
try {
|
||||
await loginUsernameRepository.saveLoginUsername(recentLoginUsername);
|
||||
yield Right(SaveRecentLoginUsernameSuccess());
|
||||
} catch(exception) {
|
||||
yield Left(SaveRecentLoginUsernameFailed(exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user