refactor: Update Note and Category models to use 'id' instead of 'uuid', and adjust related database operations
- Changed 'uuid' to 'id' in Note and Category models for consistency. - Updated database operations in NoteRepository to reflect the new 'id' field. - Modified sync models to accommodate changes in Note and Category structures. - Adjusted the handling of notes and categories during synchronization. - Refactored the note editor and home screen to use the new 'id' field. - Ensured that the 'isDirty' flag is properly set and utilized across models.
This commit is contained in:
+23
-21
@@ -98,16 +98,19 @@ class SyncCategoryPayload {
|
||||
required this.updatedAt,
|
||||
});
|
||||
|
||||
final String id; // uuid
|
||||
final String id;
|
||||
final String encryptedName;
|
||||
final int serverVersion;
|
||||
final bool isDeleted;
|
||||
final DateTime updatedAt;
|
||||
|
||||
factory SyncCategoryPayload.fromCategory(Category category) {
|
||||
factory SyncCategoryPayload.fromCategory(
|
||||
Category category, {
|
||||
required String encryptedName,
|
||||
}) {
|
||||
return SyncCategoryPayload(
|
||||
id: category.uuid,
|
||||
encryptedName: category.encryptedName,
|
||||
id: category.id,
|
||||
encryptedName: encryptedName,
|
||||
serverVersion: category.serverVersion,
|
||||
isDeleted: category.isDeleted,
|
||||
updatedAt: category.updatedAt,
|
||||
@@ -132,18 +135,18 @@ class SyncNotePayload {
|
||||
required this.encryptedTitle,
|
||||
required this.encryptedBody,
|
||||
required this.serverVersion,
|
||||
this.position = 0,
|
||||
this.position = 0.0,
|
||||
this.isDeleted = false,
|
||||
this.isPermanentlyDeleted = false,
|
||||
required this.updatedAt,
|
||||
});
|
||||
|
||||
final String id; // uuid
|
||||
final String id;
|
||||
final String? categoryId;
|
||||
final String encryptedTitle;
|
||||
final String encryptedBody;
|
||||
final int serverVersion;
|
||||
final int position;
|
||||
final double position;
|
||||
final bool isDeleted;
|
||||
final bool isPermanentlyDeleted;
|
||||
final DateTime updatedAt;
|
||||
@@ -155,12 +158,12 @@ class SyncNotePayload {
|
||||
bool isPermanentlyDeleted = false,
|
||||
}) {
|
||||
return SyncNotePayload(
|
||||
id: note.uuid,
|
||||
id: note.id,
|
||||
categoryId: note.categoryId,
|
||||
encryptedTitle: encryptedTitle,
|
||||
encryptedBody: encryptedBody,
|
||||
serverVersion: note.serverVersion,
|
||||
position: note.index,
|
||||
position: note.position,
|
||||
isDeleted: note.isDeleted,
|
||||
isPermanentlyDeleted: isPermanentlyDeleted,
|
||||
updatedAt: note.updatedAt,
|
||||
@@ -212,8 +215,7 @@ class SyncCategoryResponse {
|
||||
this.isDeleted = false,
|
||||
required this.updatedAt,
|
||||
});
|
||||
|
||||
final String id; // uuid
|
||||
final String id;
|
||||
final String encryptedName;
|
||||
final int serverVersion;
|
||||
final bool isDeleted;
|
||||
@@ -229,10 +231,10 @@ class SyncCategoryResponse {
|
||||
);
|
||||
}
|
||||
|
||||
Category toCategory() {
|
||||
Category toCategory({required String name}) {
|
||||
return Category(
|
||||
uuid: id,
|
||||
encryptedName: encryptedName,
|
||||
id: id,
|
||||
name: name,
|
||||
serverVersion: serverVersion,
|
||||
isDeleted: isDeleted,
|
||||
updatedAt: updatedAt,
|
||||
@@ -247,18 +249,17 @@ class SyncNoteResponse {
|
||||
required this.encryptedTitle,
|
||||
required this.encryptedBody,
|
||||
required this.serverVersion,
|
||||
this.position = 0,
|
||||
this.position = 0.0,
|
||||
this.isDeleted = false,
|
||||
this.isPermanentlyDeleted = false,
|
||||
required this.updatedAt,
|
||||
});
|
||||
|
||||
final String id; // uuid
|
||||
final String id;
|
||||
final String? categoryId;
|
||||
final String encryptedTitle;
|
||||
final String encryptedBody;
|
||||
final int serverVersion;
|
||||
final int position;
|
||||
final double position;
|
||||
final bool isDeleted;
|
||||
final bool isPermanentlyDeleted;
|
||||
final DateTime updatedAt;
|
||||
@@ -272,7 +273,7 @@ class SyncNoteResponse {
|
||||
encryptedTitle: _readOptionalStringValue(json['encrypted_title']),
|
||||
encryptedBody: _readOptionalStringValue(json['encrypted_body']),
|
||||
serverVersion: _readIntValue(json['serverVersion']),
|
||||
position: json['position'] as int? ?? 0,
|
||||
position: (json['position'] as num?)?.toDouble() ?? 0,
|
||||
isDeleted: json['isDeleted'] as bool? ?? false,
|
||||
isPermanentlyDeleted: json['isPermanentlyDeleted'] as bool? ?? false,
|
||||
updatedAt: DateTime.parse(json['updatedAt'] as String),
|
||||
@@ -281,15 +282,16 @@ class SyncNoteResponse {
|
||||
|
||||
Note toNote() {
|
||||
return Note(
|
||||
uuid: id,
|
||||
id: id,
|
||||
title: isPermanentlyDeleted ? '' : 'Encrypted',
|
||||
body: isPermanentlyDeleted ? '' : 'Encrypted',
|
||||
createdAt: updatedAt,
|
||||
updatedAt: updatedAt,
|
||||
index: position,
|
||||
position: position,
|
||||
serverVersion: serverVersion,
|
||||
isDeleted: isDeleted,
|
||||
categoryId: categoryId,
|
||||
isDirty: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user