TF-4169 Add Label/set method
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import 'package:jmap_dart_client/http/converter/account_id_converter.dart';
|
||||
import 'package:jmap_dart_client/http/converter/id_converter.dart';
|
||||
import 'package:jmap_dart_client/http/converter/set/set_method_properties_converter.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/method/request/set_method.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/request/request_invocation.dart';
|
||||
import 'package:labels/labels.dart';
|
||||
|
||||
class SetLabelMethod extends SetMethod<Label> {
|
||||
SetLabelMethod(super.accountId);
|
||||
|
||||
@override
|
||||
MethodName get methodName => MethodName('Label/set');
|
||||
|
||||
@override
|
||||
Set<CapabilityIdentifier> get requiredCapabilities => {
|
||||
CapabilityIdentifier.jmapCore,
|
||||
LabelsConstants.labelsCapability,
|
||||
};
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
final val = <String, dynamic>{
|
||||
'accountId': const AccountIdConverter().toJson(accountId),
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('ifInState', ifInState?.value);
|
||||
writeNotNull(
|
||||
'create',
|
||||
create?.map((id, create) =>
|
||||
SetMethodPropertiesConverter().fromMapIdToJson(id, create.toJson())),
|
||||
);
|
||||
writeNotNull(
|
||||
'update',
|
||||
update
|
||||
?.map((id, update) => SetMethodPropertiesConverter().fromMapIdToJson(
|
||||
id,
|
||||
update.toJson(),
|
||||
)),
|
||||
);
|
||||
writeNotNull(
|
||||
'destroy',
|
||||
destroy
|
||||
?.map((destroyId) => const IdConverter().toJson(destroyId))
|
||||
.toList(),
|
||||
);
|
||||
writeNotNull('#destroy', referenceDestroy?.toJson());
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [accountId, ifInState, create, update, destroy];
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import 'package:jmap_dart_client/http/converter/account_id_converter.dart';
|
||||
import 'package:jmap_dart_client/http/converter/id_converter.dart';
|
||||
import 'package:jmap_dart_client/http/converter/state_nullable_converter.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/error/set_error.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/method/response/set_response.dart';
|
||||
import 'package:labels/model/label.dart';
|
||||
|
||||
class SetLabelResponse extends SetResponse<Label> {
|
||||
SetLabelResponse(
|
||||
super.accountId, {
|
||||
super.newState,
|
||||
super.oldState,
|
||||
super.created,
|
||||
super.updated,
|
||||
super.destroyed,
|
||||
super.notCreated,
|
||||
super.notUpdated,
|
||||
super.notDestroyed,
|
||||
});
|
||||
|
||||
static SetLabelResponse deserialize(Map<String, dynamic> json) {
|
||||
return SetLabelResponse(
|
||||
const AccountIdConverter().fromJson(json['accountId'] as String),
|
||||
newState:
|
||||
const StateNullableConverter().fromJson(json['newState'] as String?),
|
||||
oldState:
|
||||
const StateNullableConverter().fromJson(json['oldState'] as String?),
|
||||
created: (json['created'] as Map<String, dynamic>?)?.map((key, value) =>
|
||||
MapEntry(const IdConverter().fromJson(key),
|
||||
Label.fromJson(value as Map<String, dynamic>))),
|
||||
updated: (json['updated'] as Map<String, dynamic>?)?.map((key, value) =>
|
||||
MapEntry(
|
||||
const IdConverter().fromJson(key),
|
||||
value != null
|
||||
? Label.fromJson(value as Map<String, dynamic>)
|
||||
: null)),
|
||||
destroyed: (json['destroyed'] as List<dynamic>?)
|
||||
?.map((id) => const IdConverter().fromJson(id))
|
||||
.toSet(),
|
||||
notCreated: (json['notCreated'] as Map<String, dynamic>?)?.map(
|
||||
(key, value) => MapEntry(
|
||||
const IdConverter().fromJson(key), SetError.fromJson(value))),
|
||||
notUpdated: (json['notUpdated'] as Map<String, dynamic>?)?.map(
|
||||
(key, value) => MapEntry(
|
||||
const IdConverter().fromJson(key), SetError.fromJson(value))),
|
||||
notDestroyed: (json['notDestroyed'] as Map<String, dynamic>?)?.map(
|
||||
(key, value) => MapEntry(
|
||||
const IdConverter().fromJson(key), SetError.fromJson(value))),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
oldState,
|
||||
newState,
|
||||
created,
|
||||
updated,
|
||||
destroyed,
|
||||
notCreated,
|
||||
notUpdated,
|
||||
notDestroyed
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user