import 'package:dio/dio.dart'; import '../models/milestone.dart'; import 'api_client.dart'; class MilestonesApi { final Dio _dio; const MilestonesApi(this._dio); Future> getAll(int projectId, {String? status}) async { try { final response = await _dio.get( '/api/projects/$projectId/milestones', queryParameters: status != null ? {'status': status} : null, ); final data = response.data as Map; final list = data['milestones'] as List; return list .map((e) => Milestone.fromJson(e as Map)) .toList(); } on DioException catch (e) { throw dioToApp(e); } } Future create( int projectId, { required String title, String? description, int orderIndex = 0, }) async { try { final response = await _dio.post( '/api/projects/$projectId/milestones', data: { 'title': title, if (description != null && description.isNotEmpty) 'description': description, 'order_index': orderIndex, }, ); return Milestone.fromJson(response.data as Map); } on DioException catch (e) { throw dioToApp(e); } } Future update( int projectId, int milestoneId, Map fields, ) async { try { final response = await _dio.patch( '/api/projects/$projectId/milestones/$milestoneId', data: fields, ); return Milestone.fromJson(response.data as Map); } on DioException catch (e) { throw dioToApp(e); } } Future delete(int projectId, int milestoneId) async { try { await _dio.delete('/api/projects/$projectId/milestones/$milestoneId'); } on DioException catch (e) { throw dioToApp(e); } } }