claude refactor
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../../../../../api/mhsl/customTimetableEvent/add/addCustomTimetableEvent.dart';
|
||||
import '../../../../../api/mhsl/customTimetableEvent/add/addCustomTimetableEventParams.dart';
|
||||
import '../../../../../api/mhsl/customTimetableEvent/customTimetableEvent.dart';
|
||||
import '../../../../../api/mhsl/customTimetableEvent/get/getCustomTimetableEventCache.dart';
|
||||
import '../../../../../api/mhsl/customTimetableEvent/get/getCustomTimetableEventParams.dart';
|
||||
import '../../../../../api/mhsl/customTimetableEvent/get/getCustomTimetableEventResponse.dart';
|
||||
import '../../../../../api/mhsl/customTimetableEvent/remove/removeCustomTimetableEvent.dart';
|
||||
import '../../../../../api/mhsl/customTimetableEvent/remove/removeCustomTimetableEventParams.dart';
|
||||
import '../../../../../api/mhsl/customTimetableEvent/update/updateCustomTimetableEvent.dart';
|
||||
import '../../../../../api/mhsl/customTimetableEvent/update/updateCustomTimetableEventParams.dart';
|
||||
import '../../../../../api/webuntis/queries/getHolidays/getHolidaysCache.dart';
|
||||
import '../../../../../api/webuntis/queries/getHolidays/getHolidaysResponse.dart';
|
||||
import '../../../../../api/webuntis/queries/getRooms/getRoomsCache.dart';
|
||||
import '../../../../../api/webuntis/queries/getRooms/getRoomsResponse.dart';
|
||||
import '../../../../../api/webuntis/queries/getSubjects/getSubjectsCache.dart';
|
||||
import '../../../../../api/webuntis/queries/getSubjects/getSubjectsResponse.dart';
|
||||
import '../../../../../api/webuntis/queries/getTimetable/getTimetableCache.dart';
|
||||
import '../../../../../api/webuntis/queries/getTimetable/getTimetableResponse.dart';
|
||||
import '../../../../../model/accountData.dart';
|
||||
|
||||
class TimetableDataProvider {
|
||||
static final DateFormat _dateFormat = DateFormat('yyyyMMdd');
|
||||
|
||||
Future<GetTimetableResponse> getWeek(DateTime startDate, DateTime endDate) {
|
||||
final completer = Completer<GetTimetableResponse>();
|
||||
GetTimetableCache(
|
||||
startdate: int.parse(_dateFormat.format(startDate)),
|
||||
enddate: int.parse(_dateFormat.format(endDate)),
|
||||
onUpdate: (data) {
|
||||
if (!completer.isCompleted) completer.complete(data);
|
||||
},
|
||||
onError: (e) {
|
||||
if (!completer.isCompleted) completer.completeError(e);
|
||||
},
|
||||
);
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
Future<GetRoomsResponse> getRooms() {
|
||||
final completer = Completer<GetRoomsResponse>();
|
||||
GetRoomsCache(onUpdate: (data) {
|
||||
if (!completer.isCompleted) completer.complete(data);
|
||||
});
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
Future<GetSubjectsResponse> getSubjects() {
|
||||
final completer = Completer<GetSubjectsResponse>();
|
||||
GetSubjectsCache(onUpdate: (data) {
|
||||
if (!completer.isCompleted) completer.complete(data);
|
||||
});
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
Future<GetHolidaysResponse> getSchoolHolidays() {
|
||||
final completer = Completer<GetHolidaysResponse>();
|
||||
GetHolidaysCache(onUpdate: (data) {
|
||||
if (!completer.isCompleted) completer.complete(data);
|
||||
});
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
Future<GetCustomTimetableEventResponse> getCustomEvents({bool renew = false}) {
|
||||
final completer = Completer<GetCustomTimetableEventResponse>();
|
||||
GetCustomTimetableEventCache(
|
||||
GetCustomTimetableEventParams(AccountData().getUserSecret()),
|
||||
renew: renew,
|
||||
onUpdate: (data) {
|
||||
if (!completer.isCompleted) completer.complete(data);
|
||||
},
|
||||
);
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
Future<void> addCustomEvent(CustomTimetableEvent event) =>
|
||||
AddCustomTimetableEvent(AddCustomTimetableEventParams(AccountData().getUserSecret(), event)).run();
|
||||
|
||||
Future<void> updateCustomEvent(String id, CustomTimetableEvent event) =>
|
||||
UpdateCustomTimetableEvent(UpdateCustomTimetableEventParams(id, event)).run();
|
||||
|
||||
Future<void> removeCustomEvent(String id) =>
|
||||
RemoveCustomTimetableEvent(RemoveCustomTimetableEventParams(id)).run();
|
||||
}
|
||||
Reference in New Issue
Block a user