claude refactorings, flutter best practices, platform dependent changes, general cleanup
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../../../../../api/mhsl/custom_timetable_event/add/add_custom_timetable_event.dart';
|
||||
import '../../../../../api/mhsl/custom_timetable_event/add/add_custom_timetable_event_params.dart';
|
||||
import '../../../../../api/mhsl/custom_timetable_event/custom_timetable_event.dart';
|
||||
import '../../../../../api/mhsl/custom_timetable_event/get/get_custom_timetable_event_cache.dart';
|
||||
import '../../../../../api/mhsl/custom_timetable_event/get/get_custom_timetable_event_params.dart';
|
||||
import '../../../../../api/mhsl/custom_timetable_event/get/get_custom_timetable_event_response.dart';
|
||||
import '../../../../../api/mhsl/custom_timetable_event/remove/remove_custom_timetable_event.dart';
|
||||
import '../../../../../api/mhsl/custom_timetable_event/remove/remove_custom_timetable_event_params.dart';
|
||||
import '../../../../../api/mhsl/custom_timetable_event/update/update_custom_timetable_event.dart';
|
||||
import '../../../../../api/mhsl/custom_timetable_event/update/update_custom_timetable_event_params.dart';
|
||||
import '../../../../../api/webuntis/queries/get_holidays/get_holidays_cache.dart';
|
||||
import '../../../../../api/webuntis/queries/get_holidays/get_holidays_response.dart';
|
||||
import '../../../../../api/webuntis/queries/get_rooms/get_rooms_cache.dart';
|
||||
import '../../../../../api/webuntis/queries/get_rooms/get_rooms_response.dart';
|
||||
import '../../../../../api/webuntis/queries/get_subjects/get_subjects_cache.dart';
|
||||
import '../../../../../api/webuntis/queries/get_subjects/get_subjects_response.dart';
|
||||
import '../../../../../api/webuntis/queries/get_timegrid_units/get_timegrid_units_cache.dart';
|
||||
import '../../../../../api/webuntis/queries/get_timegrid_units/get_timegrid_units_response.dart';
|
||||
import '../../../../../api/webuntis/queries/get_timetable/get_timetable_cache.dart';
|
||||
import '../../../../../api/webuntis/queries/get_timetable/get_timetable_response.dart';
|
||||
import '../../../../../model/account_data.dart';
|
||||
|
||||
class TimetableDataProvider {
|
||||
static final DateFormat _dateFormat = DateFormat('yyyyMMdd');
|
||||
|
||||
Future<GetTimetableResponse> getWeek(
|
||||
DateTime startDate,
|
||||
DateTime endDate, {
|
||||
void Function(Object)? onError,
|
||||
bool renew = false,
|
||||
}) async {
|
||||
GetTimetableResponse? latest;
|
||||
Object? capturedError;
|
||||
final cache = GetTimetableCache(
|
||||
startdate: int.parse(_dateFormat.format(startDate)),
|
||||
enddate: int.parse(_dateFormat.format(endDate)),
|
||||
renew: renew,
|
||||
onUpdate: (data) => latest = data,
|
||||
onError: (e) {
|
||||
capturedError = e;
|
||||
onError?.call(e);
|
||||
},
|
||||
);
|
||||
await cache.ready;
|
||||
if (latest != null) return latest!;
|
||||
throw capturedError ?? Exception('No data and no error from getWeek');
|
||||
}
|
||||
|
||||
Future<GetRoomsResponse> getRooms({
|
||||
void Function(Object)? onError,
|
||||
bool renew = false,
|
||||
}) async {
|
||||
GetRoomsResponse? latest;
|
||||
Object? capturedError;
|
||||
final cache = GetRoomsCache(
|
||||
renew: renew,
|
||||
onUpdate: (data) => latest = data,
|
||||
onError: (e) {
|
||||
capturedError = e;
|
||||
onError?.call(e);
|
||||
},
|
||||
);
|
||||
await cache.ready;
|
||||
if (latest != null) return latest!;
|
||||
throw capturedError ?? Exception('No data and no error from getRooms');
|
||||
}
|
||||
|
||||
Future<GetSubjectsResponse> getSubjects({
|
||||
void Function(Object)? onError,
|
||||
bool renew = false,
|
||||
}) async {
|
||||
GetSubjectsResponse? latest;
|
||||
Object? capturedError;
|
||||
final cache = GetSubjectsCache(
|
||||
renew: renew,
|
||||
onUpdate: (data) => latest = data,
|
||||
onError: (e) {
|
||||
capturedError = e;
|
||||
onError?.call(e);
|
||||
},
|
||||
);
|
||||
await cache.ready;
|
||||
if (latest != null) return latest!;
|
||||
throw capturedError ?? Exception('No data and no error from getSubjects');
|
||||
}
|
||||
|
||||
Future<GetHolidaysResponse> getSchoolHolidays({
|
||||
void Function(Object)? onError,
|
||||
bool renew = false,
|
||||
}) async {
|
||||
GetHolidaysResponse? latest;
|
||||
Object? capturedError;
|
||||
final cache = GetHolidaysCache(
|
||||
renew: renew,
|
||||
onUpdate: (data) => latest = data,
|
||||
onError: (e) {
|
||||
capturedError = e;
|
||||
onError?.call(e);
|
||||
},
|
||||
);
|
||||
await cache.ready;
|
||||
if (latest != null) return latest!;
|
||||
throw capturedError ?? Exception('No data and no error from getSchoolHolidays');
|
||||
}
|
||||
|
||||
Future<GetTimegridUnitsResponse> getTimegrid({bool renew = false}) async {
|
||||
GetTimegridUnitsResponse? latest;
|
||||
Object? capturedError;
|
||||
final cache = GetTimegridUnitsCache(
|
||||
renew: renew,
|
||||
onUpdate: (data) => latest = data,
|
||||
);
|
||||
await cache.ready;
|
||||
if (latest != null) return latest!;
|
||||
throw capturedError ?? Exception('No data and no error from getTimegrid');
|
||||
}
|
||||
|
||||
Future<GetCustomTimetableEventResponse> getCustomEvents({
|
||||
bool renew = false,
|
||||
void Function(Object)? onError,
|
||||
}) async {
|
||||
GetCustomTimetableEventResponse? latest;
|
||||
Object? capturedError;
|
||||
final cache = GetCustomTimetableEventCache(
|
||||
GetCustomTimetableEventParams(AccountData().getUserSecret()),
|
||||
renew: renew,
|
||||
onUpdate: (data) => latest = data,
|
||||
onError: (e) {
|
||||
capturedError = e;
|
||||
onError?.call(e);
|
||||
},
|
||||
);
|
||||
await cache.ready;
|
||||
if (latest != null) return latest!;
|
||||
throw capturedError ?? Exception('No data and no error from getCustomEvents');
|
||||
}
|
||||
|
||||
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