TF-527 Add domain layer in add new identity
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/identities/identity.dart';
|
||||||
|
|
||||||
|
class CreateNewIdentityRequest with EquatableMixin {
|
||||||
|
|
||||||
|
final Identity newIdentity;
|
||||||
|
final Id creationId;
|
||||||
|
|
||||||
|
CreateNewIdentityRequest(this.creationId, this.newIdentity);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [creationId, newIdentity];
|
||||||
|
}
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
import 'package:jmap_dart_client/jmap/identities/identity.dart';
|
import 'package:jmap_dart_client/jmap/identities/identity.dart';
|
||||||
|
import 'package:tmail_ui_user/features/manage_account/domain/model/create_new_identity_request.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/identities/identity.dart';
|
||||||
import 'package:tmail_ui_user/features/manage_account/domain/model/identities_response.dart';
|
import 'package:tmail_ui_user/features/manage_account/domain/model/identities_response.dart';
|
||||||
|
|
||||||
abstract class ManageAccountRepository {
|
abstract class ManageAccountRepository {
|
||||||
Future<IdentitiesResponse> getAllIdentities(AccountId accountId);
|
Future<IdentitiesResponse> getAllIdentities(AccountId accountId);
|
||||||
|
|
||||||
|
Future<Identity> createNewIdentity(AccountId accountId, CreateNewIdentityRequest identityRequest);
|
||||||
|
|
||||||
Future<bool> deleteIdentity(AccountId accountId, IdentityId identityId);
|
Future<bool> deleteIdentity(AccountId accountId, IdentityId identityId);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import 'package:core/core.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/identities/identity.dart';
|
||||||
|
|
||||||
|
class CreateNewIdentitySuccess extends UIState {
|
||||||
|
|
||||||
|
final Identity newIdentity;
|
||||||
|
|
||||||
|
CreateNewIdentitySuccess(this.newIdentity);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [newIdentity];
|
||||||
|
}
|
||||||
|
|
||||||
|
class CreateNewIdentityFailure extends FeatureFailure {
|
||||||
|
final dynamic exception;
|
||||||
|
|
||||||
|
CreateNewIdentityFailure(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/model/create_new_identity_request.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/create_new_identity_state.dart';
|
||||||
|
|
||||||
|
class CreateNewIdentityInteractor {
|
||||||
|
final ManageAccountRepository manageAccountRepository;
|
||||||
|
|
||||||
|
CreateNewIdentityInteractor(this.manageAccountRepository);
|
||||||
|
|
||||||
|
Stream<Either<Failure, Success>> execute(AccountId accountId, CreateNewIdentityRequest identityRequest) async* {
|
||||||
|
try {
|
||||||
|
final newIdentity = await manageAccountRepository.createNewIdentity(accountId, identityRequest);
|
||||||
|
yield Right(CreateNewIdentitySuccess(newIdentity));
|
||||||
|
} catch (exception) {
|
||||||
|
yield Left(CreateNewIdentityFailure(exception));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user