mirror of
https://github.com/vleeuwenmenno/supplements.git
synced 2025-09-11 18:29:12 +02:00
feat adds proper syncing feature
Signed-off-by: Menno van Leeuwen <menno@vleeuwen.me>
This commit is contained in:
@@ -3,7 +3,7 @@ import 'dart:convert';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import 'ingredient.dart';
|
||||
import 'sync_enums.dart';
|
||||
import '../services/database_sync_service.dart';
|
||||
|
||||
class Supplement {
|
||||
final int? id;
|
||||
@@ -21,7 +21,7 @@ class Supplement {
|
||||
// Sync metadata
|
||||
final String syncId;
|
||||
final DateTime lastModified;
|
||||
final SyncStatus syncStatus;
|
||||
final RecordSyncStatus syncStatus;
|
||||
final bool isDeleted;
|
||||
|
||||
Supplement({
|
||||
@@ -38,7 +38,7 @@ class Supplement {
|
||||
this.isActive = true,
|
||||
String? syncId,
|
||||
DateTime? lastModified,
|
||||
this.syncStatus = SyncStatus.pending,
|
||||
this.syncStatus = RecordSyncStatus.pending,
|
||||
this.isDeleted = false,
|
||||
}) : syncId = syncId ?? const Uuid().v4(),
|
||||
lastModified = lastModified ?? DateTime.now();
|
||||
@@ -122,11 +122,11 @@ class Supplement {
|
||||
? DateTime.parse(map['lastModified'])
|
||||
: DateTime.now(),
|
||||
syncStatus: map['syncStatus'] != null
|
||||
? SyncStatus.values.firstWhere(
|
||||
? RecordSyncStatus.values.firstWhere(
|
||||
(e) => e.name == map['syncStatus'],
|
||||
orElse: () => SyncStatus.pending,
|
||||
orElse: () => RecordSyncStatus.pending,
|
||||
)
|
||||
: SyncStatus.pending,
|
||||
: RecordSyncStatus.pending,
|
||||
isDeleted: (map['isDeleted'] ?? 0) == 1,
|
||||
);
|
||||
}
|
||||
@@ -145,7 +145,7 @@ class Supplement {
|
||||
bool? isActive,
|
||||
String? syncId,
|
||||
DateTime? lastModified,
|
||||
SyncStatus? syncStatus,
|
||||
RecordSyncStatus? syncStatus,
|
||||
bool? isDeleted,
|
||||
}) {
|
||||
return Supplement(
|
||||
@@ -171,14 +171,14 @@ class Supplement {
|
||||
Supplement markAsModified() {
|
||||
return copyWith(
|
||||
lastModified: DateTime.now(),
|
||||
syncStatus: SyncStatus.modified,
|
||||
syncStatus: RecordSyncStatus.modified,
|
||||
);
|
||||
}
|
||||
|
||||
/// Create a new supplement marked as synced
|
||||
Supplement markAsSynced() {
|
||||
return copyWith(
|
||||
syncStatus: SyncStatus.synced,
|
||||
syncStatus: RecordSyncStatus.synced,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ class Supplement {
|
||||
return copyWith(
|
||||
isDeleted: true,
|
||||
lastModified: DateTime.now(),
|
||||
syncStatus: SyncStatus.modified,
|
||||
syncStatus: RecordSyncStatus.modified,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user