TF-460 Add domain layer for implement get all identities
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart';
|
||||
import 'package:jmap_dart_client/jmap/identities/identity.dart';
|
||||
|
||||
class IdentitiesResponse with EquatableMixin {
|
||||
final List<Identity>? identities;
|
||||
final State? state;
|
||||
|
||||
IdentitiesResponse({
|
||||
this.identities,
|
||||
this.state
|
||||
});
|
||||
|
||||
bool hasData() {
|
||||
return identities != null
|
||||
&& identities!.isNotEmpty
|
||||
&& state != null;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [identities, state];
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/identities_response.dart';
|
||||
|
||||
abstract class ManageAccountRepository {
|
||||
Future<IdentitiesResponse> getAllIdentities(AccountId accountId);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart';
|
||||
import 'package:jmap_dart_client/jmap/identities/identity.dart';
|
||||
|
||||
class GetAllIdentitiesSuccess extends UIState {
|
||||
final List<Identity>? identities;
|
||||
final State? state;
|
||||
|
||||
GetAllIdentitiesSuccess(this.identities, this.state);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [identities, state];
|
||||
}
|
||||
|
||||
class GetAllIdentitiesFailure extends FeatureFailure {
|
||||
final dynamic exception;
|
||||
|
||||
GetAllIdentitiesFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object> get props => [exception];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import 'dart:core';
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/repository/manage_account_repository.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/state/get_all_identities_state.dart';
|
||||
|
||||
class GetAllIdentitiesInteractor {
|
||||
final ManageAccountRepository manageAccountRepository;
|
||||
|
||||
GetAllIdentitiesInteractor(this.manageAccountRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(LoadingState());
|
||||
final identitiesResponse = await manageAccountRepository.getAllIdentities(accountId);
|
||||
yield Right(GetAllIdentitiesSuccess(identitiesResponse.identities, identitiesResponse.state));
|
||||
} catch (exception) {
|
||||
yield Left(GetAllIdentitiesFailure(exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user