Files
be_happy_public/lib/data/service/news_api_service.dart
2026-05-12 12:02:40 +03:00

36 lines
1.2 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:developer' as dev;
import '../network/api_service.dart';
class NewsApiService {
final ApiService _apiService;
NewsApiService(this._apiService);
Future<Map<String, dynamic>> getNews() async {
try {
dev.log('NewsApiService: Запрос GET /news');
final response = await _apiService.getNews();
dev.log('NewsApiService: Успешно получено ${response['data']?.length ?? 0} новостей');
return response;
} catch (e, stackTrace) {
dev.log('NewsApiService: Ошибка: $e', stackTrace: stackTrace);
throw Exception('Не удалось загрузить новости: $e');
}
}
Future<Map<String, dynamic>> getNewsById(int newsId) async {
try {
dev.log('NewsApiService: Запрос GET /news/$newsId');
final response = await _apiService.getNewsById(newsId);
dev.log('NewsApiService: Успешно получена новость с ID: $newsId');
return response!;
} catch (e, stackTrace) {
dev.log('NewsApiService: Ошибка: $e', stackTrace: stackTrace);
throw Exception('Не удалось загрузить новость: $e');
}
}
}