feat(frontend): add responsable dashboard screen
This commit is contained in:
@@ -18,13 +18,20 @@ class ApiClient {
|
||||
|
||||
static const String _baseUrl = "http://localhost:3000/api";
|
||||
static const String _utilisateurEmail = "lucas.martin@ensitech.eu";
|
||||
static const String responsableEmail = "karim.benali@ensup.eu";
|
||||
|
||||
static Future<dynamic> get(String chemin) async {
|
||||
static Future<dynamic> get(
|
||||
String chemin, {
|
||||
String utilisateurEmail = _utilisateurEmail,
|
||||
}) async {
|
||||
final uri = Uri.parse("$_baseUrl$chemin");
|
||||
|
||||
late final http.Response reponse;
|
||||
try {
|
||||
reponse = await http.get(uri, headers: const {"x-user-email": _utilisateurEmail});
|
||||
reponse = await http.get(
|
||||
uri,
|
||||
headers: {"x-user-email": utilisateurEmail},
|
||||
);
|
||||
} catch (_) {
|
||||
throw const ApiException(
|
||||
"Impossible de joindre le serveur. Vérifiez que le backend est démarré.",
|
||||
@@ -37,16 +44,49 @@ class ApiClient {
|
||||
throw ApiException(_messageErreur(reponse));
|
||||
}
|
||||
|
||||
static Future<dynamic> post(String chemin, Map<String, dynamic> body) async {
|
||||
static Future<dynamic> post(
|
||||
String chemin,
|
||||
Map<String, dynamic> body, {
|
||||
String utilisateurEmail = _utilisateurEmail,
|
||||
}) async {
|
||||
final uri = Uri.parse("$_baseUrl$chemin");
|
||||
|
||||
late final http.Response reponse;
|
||||
try {
|
||||
reponse = await http.post(
|
||||
uri,
|
||||
headers: const {
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"x-user-email": _utilisateurEmail,
|
||||
"x-user-email": utilisateurEmail,
|
||||
},
|
||||
body: jsonEncode(body),
|
||||
);
|
||||
} catch (_) {
|
||||
throw const ApiException(
|
||||
"Impossible de joindre le serveur. Vérifiez que le backend est démarré.",
|
||||
);
|
||||
}
|
||||
|
||||
if (reponse.statusCode >= 200 && reponse.statusCode < 300) {
|
||||
return jsonDecode(reponse.body);
|
||||
}
|
||||
throw ApiException(_messageErreur(reponse));
|
||||
}
|
||||
|
||||
static Future<dynamic> patch(
|
||||
String chemin,
|
||||
Map<String, dynamic> body, {
|
||||
String utilisateurEmail = _utilisateurEmail,
|
||||
}) async {
|
||||
final uri = Uri.parse("$_baseUrl$chemin");
|
||||
|
||||
late final http.Response reponse;
|
||||
try {
|
||||
reponse = await http.patch(
|
||||
uri,
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"x-user-email": utilisateurEmail,
|
||||
},
|
||||
body: jsonEncode(body),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import "api_client.dart";
|
||||
|
||||
/// Appels API du tableau responsable matériel.
|
||||
class ResponsableService {
|
||||
ResponsableService._();
|
||||
|
||||
static const String _email = ApiClient.responsableEmail;
|
||||
|
||||
static Future<Map<String, dynamic>> dashboard() async {
|
||||
final reponse = await ApiClient.get(
|
||||
"/responsable/dashboard",
|
||||
utilisateurEmail: _email,
|
||||
);
|
||||
return Map<String, dynamic>.from(reponse["data"] as Map);
|
||||
}
|
||||
|
||||
static Future<List<Map<String, dynamic>>> emprunts() =>
|
||||
_liste("/responsable/emprunts");
|
||||
|
||||
static Future<List<Map<String, dynamic>>> materiels() =>
|
||||
_liste("/responsable/materiels");
|
||||
|
||||
static Future<List<Map<String, dynamic>>> anomalies() =>
|
||||
_liste("/responsable/anomalies");
|
||||
|
||||
static Future<List<Map<String, dynamic>>> notifications() =>
|
||||
_liste("/responsable/notifications");
|
||||
|
||||
static Future<List<Map<String, dynamic>>> historique() =>
|
||||
_liste("/responsable/historique");
|
||||
|
||||
static Future<Map<String, dynamic>> changerStatutAnomalie(
|
||||
int id,
|
||||
String statut,
|
||||
) async {
|
||||
final reponse = await ApiClient.patch("/responsable/anomalies/$id/statut", {
|
||||
"statut": statut,
|
||||
"observation": "Traitement depuis l'interface responsable",
|
||||
}, utilisateurEmail: _email);
|
||||
return Map<String, dynamic>.from(reponse["data"] as Map);
|
||||
}
|
||||
|
||||
static Future<List<Map<String, dynamic>>> _liste(String chemin) async {
|
||||
final reponse = await ApiClient.get(chemin, utilisateurEmail: _email);
|
||||
final data = reponse["data"] as List;
|
||||
return data.map((item) => Map<String, dynamic>.from(item as Map)).toList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user