getCourseSemesterList method
- String username
Fetches the list of available semesters for a student's course schedule.
Returns a list of semester identifiers (year and semester number) for which
course schedules are available for the given username (student ID).
This method should be called before getCourseTable to determine which semesters have course data available.
Implementation
Future<List<SemesterDto>> getCourseSemesterList(
String username,
) async {
final response = await _courseDio.post(
'Select.jsp',
data: {'code': username, 'format': '-3'},
);
// Find available course tables by reading anchor references
// Document structure: table>tr>td>img+a[href]
final document = parse(response.data);
final tableAnchors = document.querySelectorAll('table a[href]');
final tableLinks = tableAnchors.map((e) => e.attributes['href']).toList();
// Parse links and extract query parameters
// Link format: Select.jsp?format=-2&code=111360109&year=114&sem=1
return tableLinks.map((link) {
final queryParams = Uri.parse(link!).queryParameters;
return (
year: int.parse(queryParams['year']!),
term: int.parse(queryParams['sem']!),
);
}).toList();
}