feat(responsable): add anomaly and history tables

This commit is contained in:
SaidSoighiri94
2026-07-24 15:47:48 +02:00
parent ec36349bad
commit 38efe6a873
6 changed files with 1623 additions and 81 deletions
File diff suppressed because it is too large Load Diff
@@ -50,19 +50,86 @@ class ResponsableService {
return _liste("/responsable/materiels?$query");
}
static Future<List<Map<String, dynamic>>> anomalies() =>
_liste("/responsable/anomalies");
static Future<List<Map<String, dynamic>>> anomalies({
String? statut,
String? type,
String? recherche,
String tri = "dateDetection",
String ordre = "desc",
}) {
final parametres = <String, String>{
"tri": tri,
"ordre": ordre,
"statut": ?statut,
"type": ?type,
if (recherche != null && recherche.trim().isNotEmpty)
"q": recherche.trim(),
};
final query = Uri(queryParameters: parametres).query;
return _liste("/responsable/anomalies?$query");
}
static Future<List<Map<String, dynamic>>> notifications() =>
_liste("/responsable/notifications");
static Future<List<Map<String, dynamic>>> historique() =>
_liste("/responsable/historique");
static Future<List<Map<String, dynamic>>> historique({
String? action,
DateTime? dateDebut,
DateTime? dateFin,
String? recherche,
String tri = "dateAction",
String ordre = "desc",
}) {
return _liste(
"/responsable/historique?${_historiqueQuery(action: action, dateDebut: dateDebut, dateFin: dateFin, recherche: recherche, tri: tri, ordre: ordre)}",
);
}
static Future<ApiFile> exporterHistorique() => ApiClient.getFile(
"/responsable/historique/export.csv",
fallbackFileName: "historique-responsable.csv",
);
static Future<ApiFile> exporterHistorique({
String? action,
DateTime? dateDebut,
DateTime? dateFin,
String? recherche,
String tri = "dateAction",
String ordre = "desc",
}) {
final query = _historiqueQuery(
action: action,
dateDebut: dateDebut,
dateFin: dateFin,
recherche: recherche,
tri: tri,
ordre: ordre,
);
return ApiClient.getFile(
"/responsable/historique/export.csv?$query",
fallbackFileName: "historique-responsable.csv",
);
}
static String _historiqueQuery({
String? action,
DateTime? dateDebut,
DateTime? dateFin,
String? recherche,
required String tri,
required String ordre,
}) {
final finIncluse = dateFin == null
? null
: DateTime(dateFin.year, dateFin.month, dateFin.day, 23, 59, 59, 999);
return Uri(
queryParameters: {
"tri": tri,
"ordre": ordre,
"action": ?action,
if (dateDebut != null) "dateDebut": dateDebut.toUtc().toIso8601String(),
if (finIncluse != null) "dateFin": finIncluse.toUtc().toIso8601String(),
if (recherche != null && recherche.trim().isNotEmpty)
"q": recherche.trim(),
},
).query;
}
static Future<int> marquerNotificationsLues() async {
final reponse = await ApiClient.patch(