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:
+19
-24
@@ -2,63 +2,58 @@ import 'package:uuid/uuid.dart';
|
||||
|
||||
// Model: Note
|
||||
// - Representa una nota guardada en la app.
|
||||
// - `id` es el identificador local de SQLite (autoincrement).
|
||||
// - `uuid` es el identificador global sincronizado con el servidor.
|
||||
// - `index` representa el orden visual dentro de la lista.
|
||||
// - `serverVersion` se usa para resolver conflictos en sync.
|
||||
// - `isDeleted` marca eliminaciones blandas.
|
||||
class Note {
|
||||
Note({
|
||||
this.id,
|
||||
String? uuid,
|
||||
String? id,
|
||||
required this.title,
|
||||
required this.body,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
required this.index,
|
||||
required this.position,
|
||||
this.categoryId,
|
||||
this.serverVersion = 0,
|
||||
this.isDeleted = false,
|
||||
this.isPermanentlyDeleted = false,
|
||||
this.categoryId,
|
||||
}) : uuid = uuid ?? Uuid().v4();
|
||||
this.isDirty = true,
|
||||
}) : id = id ?? Uuid().v4();
|
||||
|
||||
final int? id;
|
||||
final String uuid;
|
||||
final String id;
|
||||
final String title;
|
||||
final String body;
|
||||
final DateTime createdAt;
|
||||
final DateTime updatedAt;
|
||||
final int index;
|
||||
final double position;
|
||||
final String? categoryId;
|
||||
final int serverVersion;
|
||||
final bool isDeleted;
|
||||
final bool isPermanentlyDeleted;
|
||||
final String? categoryId;
|
||||
final bool isDirty;
|
||||
|
||||
Note copyWith({
|
||||
int? id,
|
||||
String? uuid,
|
||||
String? id,
|
||||
String? title,
|
||||
String? body,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
int? index,
|
||||
double? position,
|
||||
String? categoryId,
|
||||
int? serverVersion,
|
||||
bool? isDeleted,
|
||||
bool? isPermanentlyDeleted,
|
||||
String? categoryId,
|
||||
bool? isDirty,
|
||||
}) {
|
||||
return Note(
|
||||
id: id ?? this.id,
|
||||
uuid: uuid ?? this.uuid,
|
||||
title: title ?? this.title,
|
||||
body: body ?? this.body,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
index: index ?? this.index,
|
||||
position: position ?? this.position,
|
||||
categoryId: categoryId ?? this.categoryId,
|
||||
serverVersion: serverVersion ?? this.serverVersion,
|
||||
isDeleted: isDeleted ?? this.isDeleted,
|
||||
isPermanentlyDeleted: isPermanentlyDeleted ?? this.isPermanentlyDeleted,
|
||||
categoryId: categoryId ?? this.categoryId,
|
||||
isDirty: isDirty ?? this.isDirty,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -68,9 +63,9 @@ class Note {
|
||||
return true;
|
||||
}
|
||||
|
||||
return other is Note && uuid == other.uuid;
|
||||
return other is Note && id == other.id;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => uuid.hashCode;
|
||||
}
|
||||
int get hashCode => id.hashCode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user