42 lines
994 B
Dart
42 lines
994 B
Dart
enum SyncAction { create, update, delete }
|
|
|
|
class SyncOperation {
|
|
final String id;
|
|
final String collection;
|
|
final String docId;
|
|
final SyncAction action;
|
|
final Map<String, dynamic> data;
|
|
final DateTime timestamp;
|
|
|
|
SyncOperation({
|
|
required this.id,
|
|
required this.collection,
|
|
required this.docId,
|
|
required this.action,
|
|
required this.data,
|
|
required this.timestamp,
|
|
});
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
'id': id,
|
|
'collection': collection,
|
|
'docId': docId,
|
|
'action': action.name,
|
|
'data': data,
|
|
'timestamp': timestamp.toIso8601String(),
|
|
};
|
|
}
|
|
|
|
factory SyncOperation.fromMap(Map<String, dynamic> map) {
|
|
return SyncOperation(
|
|
id: map['id'],
|
|
collection: map['collection'],
|
|
docId: map['docId'],
|
|
action: SyncAction.values.firstWhere((e) => e.name == map['action']),
|
|
data: Map<String, dynamic>.from(map['data']),
|
|
timestamp: DateTime.parse(map['timestamp']),
|
|
);
|
|
}
|
|
}
|