add notification, fix appbar,fix style subscription

This commit is contained in:
2026-05-21 12:19:06 +03:00
parent e7d2154d98
commit c996d0847f
60 changed files with 774 additions and 365 deletions

View File

@@ -1038,6 +1038,55 @@ class ApiService {
return controller.stream;
}
Future<List<Map<String, dynamic>>> getNotifications() async {
final url = Uri.parse('$baseUrl/notification/client');
final accessToken = await _securityService.getAccessToken();
if (accessToken == null) {
print("APISERVICE Error: Access token is null.");
throw UnauthorizedException();
}
print("GET NOTIFICATIONS REQUEST:");
print("URL: $url");
final response = await http.get(
url,
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer $accessToken",
},
);
print("GET NOTIFICATIONS RESPONSE:");
print("STATUS: ${response.statusCode}");
print("BODY: ${response.body}");
if (response.statusCode == 200) {
final data = jsonDecode(utf8.decode(response.bodyBytes));
// ✅ Проверяем, является ли ответ массивом или объектом с data[]
if (data is List) {
return data.cast<Map<String, dynamic>>();
} else if (data is Map<String, dynamic>) {
final list = data['data'];
if (list is List) {
return list.cast<Map<String, dynamic>>();
} else {
throw Exception('Expected a List under "data" but got ${list.runtimeType}');
}
} else {
throw Exception('Expected a List or Map but got ${data.runtimeType}');
}
} else if (response.statusCode == 401) {
throw UnauthorizedException();
} else if (response.statusCode == 403) {
throw AuthBlockException();
}
throw Exception('Ошибка сервера: ${response.statusCode}');
}
Future<List<Certificate>> getCertificates() async {
try {
final response = await _dio.get(

View File

@@ -33,4 +33,22 @@ class NotificationRepositoryImpl implements NotificationRepository {
void closeStream() {
// соединение закрывается автоматически при отписке от stream
}
@override
Future<List<ClientNotification>> getNotifications() async {
try {
final List<Map<String, dynamic>> data = await _apiService.getNotifications();
final notifications = data.map((json) {
final dto = ClientNotificationDto.fromJson(json);
return dto.toEntity();
}).toList();
// dev.log('NotificationRepository: Загружено ${notifications.length} уведомлений');
return notifications;
} catch (e, stackTrace) {
// dev.log('NotificationRepository: Ошибка: $e', stackTrace: stackTrace);
throw Exception('Не удалось загрузить уведомления: $e');
}
}
}