import 'package:dio/dio.dart'; import '../models/briefing_feed.dart'; import '../models/news_item.dart'; import 'api_client.dart'; class NewsApi { final Dio _dio; const NewsApi(this._dio); /// GET /api/briefing/news /// Returns up to [limit] items starting at [offset], optionally filtered by [feedId]. Future> getNewsItems({ int days = 90, int limit = 40, int offset = 0, int? feedId, }) async { try { final params = { 'days': days, 'limit': limit, 'offset': offset, if (feedId != null) 'feed_id': feedId, }; final response = await _dio.get( '/api/briefing/news', queryParameters: params, ); final data = response.data as Map; final list = data['items'] as List; return list .map((e) => NewsItem.fromJson(e as Map)) .toList(); } on DioException catch (e) { throw dioToApp(e); } } /// GET /api/briefing/feeds Future> getFeeds() async { try { final response = await _dio.get('/api/briefing/feeds'); final list = response.data as List; return list .map((e) => BriefingFeed.fromJson(e as Map)) .toList(); } on DioException catch (e) { throw dioToApp(e); } } }