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,42 @@
|
||||
import '../models/note.dart';
|
||||
import '../repositories/note_repository.dart';
|
||||
import '../services/api_client.dart';
|
||||
|
||||
class RemoteNoteRepository implements NoteRepository {
|
||||
final ApiClient _api;
|
||||
|
||||
RemoteNoteRepository({required ApiClient api}) : _api = api;
|
||||
|
||||
@override
|
||||
Future<List<Note>> getAll() async {
|
||||
final response = await _api.get('/notes/');
|
||||
final List data = response.data as List;
|
||||
return data.map((json) => Note.fromJson(json as Map<String, dynamic>)).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Note?> getById(String id) async {
|
||||
try {
|
||||
final response = await _api.get('/notes/$id');
|
||||
return Note.fromJson(response.data as Map<String, dynamic>);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Note> save(Note note) async {
|
||||
final response = await _api.post('/notes/', note.toJson());
|
||||
return Note.fromJson(response.data as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
Future<Note> update(Note note) async {
|
||||
final response = await _api.put('/notes/${note.id}', note.toJson());
|
||||
return Note.fromJson(response.data as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> delete(String id) async {
|
||||
await _api.delete('/notes/$id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user