TF-4233 Implement edit label action
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:labels/model/label.dart';
|
||||
import 'package:tmail_ui_user/features/labels/domain/model/edit_label_request.dart';
|
||||
|
||||
abstract class LabelDatasource {
|
||||
Future<List<Label>> getAllLabels(AccountId accountId);
|
||||
|
||||
Future<Label> createNewLabel(AccountId accountId, Label labelData);
|
||||
|
||||
Future<Label> editLabel(AccountId accountId, EditLabelRequest labelRequest);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:labels/model/label.dart';
|
||||
import 'package:tmail_ui_user/features/labels/data/datasource/label_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/labels/data/network/label_api.dart';
|
||||
import 'package:tmail_ui_user/features/labels/domain/model/edit_label_request.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
|
||||
|
||||
class LabelDatasourceImpl extends LabelDatasource {
|
||||
@@ -23,4 +24,11 @@ class LabelDatasourceImpl extends LabelDatasource {
|
||||
return await _labelApi.createNewLabel(accountId, labelData);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Label> editLabel(AccountId accountId, EditLabelRequest labelRequest) {
|
||||
return Future.sync(() async {
|
||||
return await _labelApi.editLabel(accountId, labelRequest);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
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/id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/patch_object.dart';
|
||||
import 'package:jmap_dart_client/jmap/jmap_request.dart';
|
||||
import 'package:labels/labels.dart';
|
||||
import 'package:tmail_ui_user/features/base/mixin/handle_error_mixin.dart';
|
||||
import 'package:tmail_ui_user/features/labels/domain/model/edit_label_request.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class LabelApi with HandleSetErrorMixin {
|
||||
@@ -57,4 +59,40 @@ class LabelApi with HandleSetErrorMixin {
|
||||
throw parseErrorForSetResponse(response, generateCreateId);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Label> editLabel(
|
||||
AccountId accountId,
|
||||
EditLabelRequest labelRequest,
|
||||
) async {
|
||||
final labelId = labelRequest.labelId;
|
||||
final newLabel = labelRequest.newLabel;
|
||||
|
||||
final method = SetLabelMethod(accountId)
|
||||
..addUpdates({
|
||||
labelId: PatchObject(newLabel.toJson())
|
||||
});
|
||||
|
||||
final builder = JmapRequestBuilder(_httpClient, ProcessingInvocation());
|
||||
final invocation = builder.invocation(method);
|
||||
|
||||
final result =
|
||||
await (builder..usings(method.requiredCapabilities)).build().execute();
|
||||
|
||||
final response = result.parse<SetLabelResponse>(
|
||||
invocation.methodCallId,
|
||||
SetLabelResponse.deserialize,
|
||||
);
|
||||
|
||||
final labelUpdated = response?.updated?[labelId];
|
||||
|
||||
if (labelUpdated != null) {
|
||||
final newLabelUpdated = newLabel.copyWith(
|
||||
id: labelId,
|
||||
keyword: labelRequest.labelKeyword,
|
||||
);
|
||||
return newLabelUpdated;
|
||||
} else {
|
||||
throw parseErrorForSetResponse(response, labelId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:labels/model/label.dart';
|
||||
import 'package:tmail_ui_user/features/labels/data/datasource/label_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/labels/domain/model/edit_label_request.dart';
|
||||
import 'package:tmail_ui_user/features/labels/domain/repository/label_repository.dart';
|
||||
|
||||
class LabelRepositoryImpl extends LabelRepository {
|
||||
@@ -17,4 +18,9 @@ class LabelRepositoryImpl extends LabelRepository {
|
||||
Future<Label> createNewLabel(AccountId accountId, Label labelData) {
|
||||
return _labelDatasource.createNewLabel(accountId, labelData);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Label> editLabel(AccountId accountId, EditLabelRequest labelRequest) {
|
||||
return _labelDatasource.editLabel(accountId, labelRequest);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user