diff --git a/lib/fetching/timetable.dart b/lib/fetching/timetable.dart index 584ef8d774fa83106ecdff10bad944cb55cd6233..cc7bfa8fdd68121832af8a95229693d65e60eba4 100644 --- a/lib/fetching/timetable.dart +++ b/lib/fetching/timetable.dart @@ -9,21 +9,27 @@ import '../untis/teacher.dart'; import '../untis/timetable.dart'; import 'cacheable.dart'; -typedef TimetableOptions = (int classId, DateTime date); +typedef TimetableOptions = (ElementType type, int elementId, DateTime date); class CacheableTimetable extends Cacheable<TimetableData> { final DateTime date; - final int classId; + final ElementType type; + final int elementId; - CacheableTimetable(super.untis, {required this.date, required this.classId}); + CacheableTimetable( + super.untis, { + required this.date, + required this.type, + required this.elementId, + }); @override RequestOptions get request => ( 'timetable/weekly/data', 'GET', { - 'elementType': '${ElementType.classGroup.id}', - 'elementId': '$classId', + 'elementType': '${type.id}', + 'elementId': '$elementId', 'date': date.toUntisDate(), 'formatId': '2', 'filter.departmentId': '-1', diff --git a/lib/main.dart b/lib/main.dart index 7106dadbc334c9485319abe6645651b5f25f423e..9bd28bc65bbcab34c58de1fe677e1384d73485ee 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -9,6 +9,7 @@ import 'dialogs/error_dialog.dart'; import 'drawer/drawer.dart'; import 'timetable/timetable.dart'; import 'toolbar/toolbar.dart'; +import 'untis/element_type.dart'; import 'untis/fetch.dart'; import 'untis/timetable.dart'; import 'user/save_state.dart'; @@ -108,8 +109,14 @@ class _MyHomePageState extends State<MyHomePage> { final profile = await appContext.profile.firstNotNull; final selectedClasses = profile.selectedClasses; - final allTimetables = await Future.wait(selectedClasses.map((classid) { - return Future(() => untis.timetableOf(classid, date).fetched); + final allTimetables = await Future.wait(selectedClasses.map((classId) { + final cacheable = untis.timetableOf( + type: ElementType.classGroup, + elementId: classId, + date: date, + ); + + return Future(() => cacheable.fetched); })); setState(() { diff --git a/lib/untis/fetch.dart b/lib/untis/fetch.dart index 793fc15dae31f1c1e7af85dd48f728f8caee8b30..0d84c019b85440157d710e1ed056d1b81210b19a 100644 --- a/lib/untis/fetch.dart +++ b/lib/untis/fetch.dart @@ -40,10 +40,16 @@ class UntisFetch { final Map<TimetableOptions, CacheableTimetable> _timetables = {}; - CacheableTimetable timetableOf(int classId, DateTime date) { - final TimetableOptions options = (classId, date); + CacheableTimetable timetableOf({ + required ElementType type, + required int elementId, + required DateTime date, + }) { + final TimetableOptions options = (type, elementId, date); return _timetables.putIfAbsent( - options, () => CacheableTimetable(this, date: date, classId: classId)); + options, + () => CacheableTimetable(this, + date: date, type: type, elementId: elementId)); } Uri _makeUri(RequestOptions options) { diff --git a/test/untis_test.dart b/test/untis_test.dart index 8c730fc9390ebe8fd1fede9f802e29e51d85b8f4..7458576f2fefa22feaf70875203a448d82fc24df 100644 --- a/test/untis_test.dart +++ b/test/untis_test.dart @@ -1,10 +1,18 @@ +import 'package:better_untis/untis/element_type.dart'; import 'package:better_untis/untis/fetch.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { test('Basic Untis call', () async { final untis = UntisFetch(); - final timetable = await untis.timetableOf(20000, DateTime.now()).fetched; + + final cacheable = untis.timetableOf( + type: ElementType.classGroup, + elementId: 20000, + date: DateTime.now(), + ); + + final timetable = await cacheable.fetched; print(timetable.lessons); });