mirror of
https://github.com/cyberbread-ru/notepad.git
synced 2026-07-14 12:51:01 +03:00
initial vibecoded release
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../models/note.dart';
|
||||
import '../repositories/local_note_repository.dart';
|
||||
import 'sync_service.dart';
|
||||
|
||||
class NoteService {
|
||||
final LocalNoteRepository _local;
|
||||
final SyncService? _sync;
|
||||
final _uuid = const Uuid();
|
||||
|
||||
NoteService({
|
||||
required LocalNoteRepository local,
|
||||
SyncService? sync,
|
||||
}) : _local = local,
|
||||
_sync = sync;
|
||||
|
||||
Future<List<Note>> getAllNotes() => _local.getAll();
|
||||
|
||||
Future<Note> createNote({String title = '', String content = ''}) async {
|
||||
final note = Note(
|
||||
id: _uuid.v4(),
|
||||
title: title,
|
||||
content: content,
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
);
|
||||
await _local.save(note);
|
||||
return note;
|
||||
}
|
||||
|
||||
Future<Note> updateNote(Note note) async {
|
||||
final updated = note.copyWith(updatedAt: DateTime.now());
|
||||
await _local.save(updated);
|
||||
return updated;
|
||||
}
|
||||
|
||||
Future<void> deleteNote(String id) async {
|
||||
await _local.delete(id);
|
||||
}
|
||||
|
||||
/// Manual backup — push everything to the server.
|
||||
Future<void> triggerBackup() async {
|
||||
if (_sync == null) throw Exception('Backup not configured');
|
||||
await _sync!.pushAll();
|
||||
}
|
||||
|
||||
/// Restore — pull everything from the server.
|
||||
Future<void> triggerRestore() async {
|
||||
if (_sync == null) throw Exception('Backup not configured');
|
||||
await _sync!.pullAll();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user