import 'package:dio/dio.dart'; import '../models/note.dart'; import 'api_client.dart'; class NotesApi { final Dio _dio; const NotesApi(this._dio); Future> getAll() async { try { final response = await _dio.get('/api/notes'); final data = response.data as Map; final list = data['notes'] as List; return list.map((e) => Note.fromJson(e as Map)).toList(); } on DioException catch (e) { throw dioToApp(e); } } Future getOne(int id) async { try { final response = await _dio.get('/api/notes/$id'); return Note.fromJson(response.data as Map); } on DioException catch (e) { throw dioToApp(e); } } Future create(String title, String body) async { try { final response = await _dio.post('/api/notes', data: { 'title': title, 'body': body, }); return Note.fromJson(response.data as Map); } on DioException catch (e) { throw dioToApp(e); } } Future update(int id, String title, String body) async { try { final response = await _dio.put('/api/notes/$id', data: { 'title': title, 'body': body, }); return Note.fromJson(response.data as Map); } on DioException catch (e) { throw dioToApp(e); } } Future delete(int id) async { try { await _dio.delete('/api/notes/$id'); } on DioException catch (e) { throw dioToApp(e); } } }