39 lines
1.1 KiB
Dart
39 lines
1.1 KiB
Dart
import 'package:em2rp/services/api_service.dart';
|
|
|
|
/// Repository pour gérer toutes les opérations sur les alertes.
|
|
class AlertRepository {
|
|
final ApiService _apiService;
|
|
|
|
AlertRepository(this._apiService);
|
|
|
|
/// Récupère toutes les alertes
|
|
Future<List<Map<String, dynamic>>> getAlerts() async {
|
|
try {
|
|
final result = await _apiService.call('getAlerts', {});
|
|
final alerts = result['alerts'] as List<dynamic>?;
|
|
if (alerts == null) return [];
|
|
return alerts.map((e) => e as Map<String, dynamic>).toList();
|
|
} catch (e) {
|
|
throw Exception('Erreur lors de la récupération des alertes: $e');
|
|
}
|
|
}
|
|
|
|
/// Marque une alerte comme lue
|
|
Future<void> markAlertAsRead(String alertId) async {
|
|
try {
|
|
await _apiService.call('markAlertAsRead', {'alertId': alertId});
|
|
} catch (e) {
|
|
throw Exception('Erreur lors du marquage de l\'alerte comme lue: $e');
|
|
}
|
|
}
|
|
|
|
/// Supprime une alerte
|
|
Future<void> deleteAlert(String alertId) async {
|
|
try {
|
|
await _apiService.call('deleteAlert', {'alertId': alertId});
|
|
} catch (e) {
|
|
throw Exception('Erreur lors de la suppression de l\'alerte: $e');
|
|
}
|
|
}
|
|
}
|