getExamsDone method
Recupera gli esami giĆ sostenuti
Implementation
Future<List<Exam>> getExamsDone(String studentID) async {
try {
final url = Uri.parse('$endpoint/studente/$studentID/esamiall?ingresso=$token');
final response = await http.get(
url,
headers: {'Accept': 'application/json'},
);
if (response.statusCode == 200) {
final Map<String, dynamic> data = jsonDecode(response.body);
if (data['ritorno'] == null || data['ritorno']['esami'] == null) {
throw Exception('Nessun dato trovato nella risposta.');
}
final List<dynamic> examsJson = data['ritorno']['esami'] as List;
return examsJson.map((e) => Exam.fromJson(e)).toList();
} else {
throw Exception('Errore nella richiesta: ${response.statusCode} - ${response.reasonPhrase}');
}
} catch (e) {
throw Exception('Errore durante il recupero degli esami sostenuti: $e');
}
}