TF-561 Fix edit identity
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.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:tmail_ui_user/features/manage_account/domain/model/edit_identity_request.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/identities_response.dart';
|
||||
|
||||
abstract class ManageAccountDataSource {
|
||||
Future<IdentitiesResponse> getAllIdentities(AccountId accountId);
|
||||
Future<IdentitiesResponse> getAllIdentities(AccountId accountId, {Properties? properties});
|
||||
|
||||
Future<Identity> createNewIdentity(AccountId accountId, CreateNewIdentityRequest identityRequest);
|
||||
|
||||
Future<bool> deleteIdentity(AccountId accountId, IdentityId identityId);
|
||||
|
||||
Future<Identity> editIdentity(AccountId accountId, EditIdentityRequest identityRequest);
|
||||
Future<bool> editIdentity(AccountId accountId, EditIdentityRequest editIdentityRequest);
|
||||
}
|
||||
+5
-4
@@ -1,4 +1,5 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/identities/identity.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/data/datasource/manage_account_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/data/network/manage_account_api.dart';
|
||||
@@ -13,9 +14,9 @@ class ManageAccountDataSourceImpl extends ManageAccountDataSource {
|
||||
ManageAccountDataSourceImpl(this.manageAccountAPI);
|
||||
|
||||
@override
|
||||
Future<IdentitiesResponse> getAllIdentities(AccountId accountId) {
|
||||
Future<IdentitiesResponse> getAllIdentities(AccountId accountId, {Properties? properties}) {
|
||||
return Future.sync(() async {
|
||||
return await manageAccountAPI.getAllIdentities(accountId);
|
||||
return await manageAccountAPI.getAllIdentities(accountId, properties: properties);
|
||||
}).catchError((error) {
|
||||
throw error;
|
||||
});
|
||||
@@ -40,9 +41,9 @@ class ManageAccountDataSourceImpl extends ManageAccountDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Identity> editIdentity(AccountId accountId, EditIdentityRequest identityRequest) {
|
||||
Future<bool> editIdentity(AccountId accountId, EditIdentityRequest editIdentityRequest) {
|
||||
return Future.sync(() async {
|
||||
return await manageAccountAPI.editIdentity(accountId, identityRequest);
|
||||
return await manageAccountAPI.editIdentity(accountId, editIdentityRequest);
|
||||
}).catchError((error) {
|
||||
throw error;
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:jmap_dart_client/http/http_client.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/patch_object.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/identities/get/get_identity_method.dart';
|
||||
import 'package:jmap_dart_client/jmap/identities/get/get_identity_response.dart';
|
||||
import 'package:jmap_dart_client/jmap/identities/identity.dart';
|
||||
@@ -19,10 +20,13 @@ class ManageAccountAPI {
|
||||
|
||||
ManageAccountAPI(this._httpClient);
|
||||
|
||||
Future<IdentitiesResponse> getAllIdentities(AccountId accountId) async {
|
||||
Future<IdentitiesResponse> getAllIdentities(AccountId accountId, {Properties? properties}) async {
|
||||
final processingInvocation = ProcessingInvocation();
|
||||
final jmapRequestBuilder = JmapRequestBuilder(_httpClient, processingInvocation);
|
||||
final getIdentityMethod = GetIdentityMethod(accountId);
|
||||
if (properties != null) {
|
||||
getIdentityMethod.addProperties(properties);
|
||||
}
|
||||
final queryInvocation = jmapRequestBuilder.invocation(getIdentityMethod);
|
||||
|
||||
final result = await (jmapRequestBuilder
|
||||
@@ -85,10 +89,10 @@ class ManageAccountAPI {
|
||||
});
|
||||
}
|
||||
|
||||
Future<Identity> editIdentity(AccountId accountId, EditIdentityRequest identityRequest) async {
|
||||
Future<bool> editIdentity(AccountId accountId, EditIdentityRequest editIdentityRequest) async {
|
||||
final setIdentityMethod = SetIdentityMethod(accountId)
|
||||
..addUpdates({
|
||||
identityRequest.identityId.id : PatchObject({})
|
||||
editIdentityRequest.identityId.id : PatchObject(editIdentityRequest.identityRequest.toJson())
|
||||
});
|
||||
|
||||
final requestBuilder = JmapRequestBuilder(_httpClient, ProcessingInvocation());
|
||||
@@ -105,7 +109,7 @@ class ManageAccountAPI {
|
||||
SetIdentityResponse.deserialize);
|
||||
|
||||
return Future.sync(() async {
|
||||
return setIdentityResponse!.updated![identityRequest.identityId]!;
|
||||
return setIdentityResponse?.updated?.containsKey(editIdentityRequest.identityId.id) == true;
|
||||
}).catchError((error) {
|
||||
throw error;
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/identities/identity.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/data/datasource/manage_account_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/create_new_identity_request.dart';
|
||||
@@ -13,8 +14,8 @@ class ManageAccountRepositoryImpl extends ManageAccountRepository {
|
||||
ManageAccountRepositoryImpl(this.dataSource);
|
||||
|
||||
@override
|
||||
Future<IdentitiesResponse> getAllIdentities(AccountId accountId) {
|
||||
return dataSource.getAllIdentities(accountId);
|
||||
Future<IdentitiesResponse> getAllIdentities(AccountId accountId, {Properties? properties}) {
|
||||
return dataSource.getAllIdentities(accountId, properties: properties);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -28,7 +29,7 @@ class ManageAccountRepositoryImpl extends ManageAccountRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Identity> editIdentity(AccountId accountId, EditIdentityRequest identityRequest) {
|
||||
return dataSource.editIdentity(accountId, identityRequest);
|
||||
Future<bool> editIdentity(AccountId accountId, EditIdentityRequest editIdentityRequest) {
|
||||
return dataSource.editIdentity(accountId, editIdentityRequest);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:jmap_dart_client/jmap/identities/identity.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
class EditIdentityRequest with EquatableMixin {
|
||||
|
||||
final Identity newIdentity;
|
||||
final IdentityRequestDto identityRequest;
|
||||
final IdentityId identityId;
|
||||
|
||||
EditIdentityRequest(this.identityId, this.newIdentity);
|
||||
EditIdentityRequest({required this.identityId, required this.identityRequest});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [identityId, newIdentity];
|
||||
List<Object?> get props => [identityId, identityRequest];
|
||||
}
|
||||
@@ -1,15 +1,16 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.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:tmail_ui_user/features/manage_account/domain/model/edit_identity_request.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/identities_response.dart';
|
||||
|
||||
abstract class ManageAccountRepository {
|
||||
Future<IdentitiesResponse> getAllIdentities(AccountId accountId);
|
||||
Future<IdentitiesResponse> getAllIdentities(AccountId accountId, {Properties? properties});
|
||||
|
||||
Future<Identity> createNewIdentity(AccountId accountId, CreateNewIdentityRequest identityRequest);
|
||||
|
||||
Future<bool> deleteIdentity(AccountId accountId, IdentityId identityId);
|
||||
|
||||
Future<Identity> editIdentity(AccountId accountId, EditIdentityRequest identityRequest);
|
||||
Future<bool> editIdentity(AccountId accountId, EditIdentityRequest editIdentityRequest);
|
||||
}
|
||||
@@ -1,14 +1,11 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:jmap_dart_client/jmap/identities/identity.dart';
|
||||
|
||||
class EditIdentitySuccess extends UIState {
|
||||
|
||||
final Identity newIdentity;
|
||||
|
||||
EditIdentitySuccess(this.newIdentity);
|
||||
EditIdentitySuccess();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [newIdentity];
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class EditIdentityFailure extends FeatureFailure {
|
||||
|
||||
@@ -12,10 +12,13 @@ class EditIdentityInteractor {
|
||||
|
||||
EditIdentityInteractor(this.manageAccountRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, EditIdentityRequest identityRequest) async* {
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
AccountId accountId,
|
||||
EditIdentityRequest editIdentityRequest
|
||||
) async* {
|
||||
try {
|
||||
final newIdentity = await manageAccountRepository.editIdentity(accountId, identityRequest);
|
||||
yield Right(EditIdentitySuccess(newIdentity));
|
||||
final result = await manageAccountRepository.editIdentity(accountId, editIdentityRequest);
|
||||
yield result ? Right(EditIdentitySuccess()) : Left(EditIdentityFailure(null));
|
||||
} catch (exception) {
|
||||
yield Left(EditIdentityFailure(exception));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:core';
|
||||
import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.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';
|
||||
|
||||
@@ -11,10 +12,10 @@ class GetAllIdentitiesInteractor {
|
||||
|
||||
GetAllIdentitiesInteractor(this.manageAccountRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, {Properties? properties}) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(LoadingState());
|
||||
final identitiesResponse = await manageAccountRepository.getAllIdentities(accountId);
|
||||
final identitiesResponse = await manageAccountRepository.getAllIdentities(accountId, properties: properties);
|
||||
yield Right(GetAllIdentitiesSuccess(identitiesResponse.identities, identitiesResponse.state));
|
||||
} catch (exception) {
|
||||
yield Left(GetAllIdentitiesFailure(exception));
|
||||
|
||||
+13
-5
@@ -1,12 +1,13 @@
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:jmap_dart_client/jmap/identities/identity.dart';
|
||||
import 'package:model/extensions/identity_extension.dart';
|
||||
import 'package:model/extensions/list_identities_extension.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_controller.dart';
|
||||
import 'package:tmail_ui_user/features/identity_creator/presentation/model/identity_creator_arguments.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/create_new_identity_request.dart';
|
||||
@@ -296,16 +297,23 @@ class IdentitiesController extends BaseController {
|
||||
identity: identity,
|
||||
actionType: IdentityActionType.edit));
|
||||
|
||||
log('IdentitiesController::goToEditIdentity(): $newIdentity');
|
||||
_editIdentityAction(accountId, newIdentity);
|
||||
if (newIdentity is Identity) {
|
||||
log('IdentitiesController::goToEditIdentity(): $newIdentity');
|
||||
_editIdentityAction(accountId, EditIdentityRequest(
|
||||
identityId: identity.id!,
|
||||
identityRequest: newIdentity.toIdentityRequest()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _editIdentityAction(AccountId accountId, EditIdentityRequest identityRequest) async {
|
||||
consumeState(_editIdentityInteractor.execute(accountId, identityRequest));
|
||||
void _editIdentityAction(AccountId accountId, EditIdentityRequest editIdentityRequest) async {
|
||||
log('IdentitiesController::_editIdentityAction(): $editIdentityRequest');
|
||||
consumeState(_editIdentityInteractor.execute(accountId, editIdentityRequest));
|
||||
}
|
||||
|
||||
void _editIdentitySuccess(EditIdentitySuccess success) {
|
||||
log('IdentitiesController::_editIdentitySuccess(): $success');
|
||||
if (currentOverlayContext != null && currentContext != null) {
|
||||
_appToast.showToastWithIcon(
|
||||
currentOverlayContext!,
|
||||
|
||||
Reference in New Issue
Block a user