getCalendar method

Future<List<CalendarEventDto>> getCalendar(
  1. DateTime startDate,
  2. DateTime endDate
)

Fetches academic calendar events within a date range.

Returns a list of calendar events (e.g., holidays, exam periods, registration deadlines) between startDate and endDate inclusive.

Requires an active portal session (call login first).

Implementation

Future<List<CalendarEventDto>> getCalendar(
  DateTime startDate,
  DateTime endDate,
) async {
  final formatter = DateFormat('yyyy/MM/dd');
  final response = await _portalDio.get(
    'calModeApp.do',
    queryParameters: {
      'startDate': formatter.format(startDate),
      'endDate': formatter.format(endDate),
    },
  );

  final List<dynamic> events = jsonDecode(response.data);
  String? normalizeEmpty(String? value) =>
      value?.isNotEmpty == true ? value : null;

  return events.map<CalendarEventDto>((e) {
    return (
      id: e['id'] as int?,
      calStart: e['calStart'] as int?,
      calEnd: e['calEnd'] as int?,
      allDay: normalizeEmpty(e['allDay'] as String?),
      calTitle: normalizeEmpty(e['calTitle'] as String?),
      calPlace: normalizeEmpty(e['calPlace'] as String?),
      calContent: normalizeEmpty(e['calContent'] as String?),
      ownerName: normalizeEmpty(e['ownerName'] as String?),
      creatorName: normalizeEmpty(e['creatorName'] as String?),
      isHoliday: normalizeEmpty(e['isHoliday'] as String?),
    );
  }).toList();
}