dart format
This commit is contained in:
@@ -9,7 +9,8 @@ import 'authenticate_response.dart';
|
||||
class Authenticate extends WebuntisApi {
|
||||
AuthenticateParams param;
|
||||
|
||||
Authenticate(this.param) : super('authenticate', param, authenticatedResponse: false);
|
||||
Authenticate(this.param)
|
||||
: super('authenticate', param, authenticatedResponse: false);
|
||||
|
||||
@override
|
||||
Future<AuthenticateResponse> run() async {
|
||||
@@ -17,7 +18,11 @@ class Authenticate extends WebuntisApi {
|
||||
try {
|
||||
final rawAnswer = await query(this);
|
||||
final decoded = jsonDecode(rawAnswer) as Map<String, dynamic>;
|
||||
final response = finalize(AuthenticateResponse.fromJson(decoded['result'] as Map<String, dynamic>));
|
||||
final response = finalize(
|
||||
AuthenticateResponse.fromJson(
|
||||
decoded['result'] as Map<String, dynamic>,
|
||||
),
|
||||
);
|
||||
_lastResponse = response;
|
||||
if (!awaitedResponse.isCompleted) awaitedResponse.complete();
|
||||
return response;
|
||||
@@ -40,23 +45,22 @@ class Authenticate extends WebuntisApi {
|
||||
|
||||
static Future<void> createSession() async {
|
||||
_lastResponse = await Authenticate(
|
||||
AuthenticateParams(
|
||||
user: AccountData().getUsername(),
|
||||
password: AccountData().getPassword(),
|
||||
)
|
||||
AuthenticateParams(
|
||||
user: AccountData().getUsername(),
|
||||
password: AccountData().getPassword(),
|
||||
),
|
||||
).run();
|
||||
}
|
||||
|
||||
static Future<AuthenticateResponse> getSession() async {
|
||||
if(awaitingResponse) {
|
||||
if (awaitingResponse) {
|
||||
await awaitedResponse.future;
|
||||
}
|
||||
|
||||
if(_lastResponse == null) {
|
||||
if (_lastResponse == null) {
|
||||
awaitingResponse = true;
|
||||
await createSession();
|
||||
}
|
||||
return _lastResponse!;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@ part 'authenticate_params.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class AuthenticateParams extends ApiParams {
|
||||
|
||||
String user;
|
||||
String password;
|
||||
|
||||
AuthenticateParams({required this.user, required this.password});
|
||||
factory AuthenticateParams.fromJson(Map<String, dynamic> json) => _$AuthenticateParamsFromJson(json);
|
||||
factory AuthenticateParams.fromJson(Map<String, dynamic> json) =>
|
||||
_$AuthenticateParamsFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$AuthenticateParamsToJson(this);
|
||||
}
|
||||
|
||||
@@ -6,14 +6,19 @@ part 'authenticate_response.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class AuthenticateResponse extends ApiResponse {
|
||||
|
||||
String sessionId;
|
||||
int personType;
|
||||
int personId;
|
||||
int klasseId;
|
||||
|
||||
AuthenticateResponse(this.sessionId, this.personType, this.personId, this.klasseId);
|
||||
AuthenticateResponse(
|
||||
this.sessionId,
|
||||
this.personType,
|
||||
this.personId,
|
||||
this.klasseId,
|
||||
);
|
||||
|
||||
factory AuthenticateResponse.fromJson(Map<String, dynamic> json) => _$AuthenticateResponseFromJson(json);
|
||||
factory AuthenticateResponse.fromJson(Map<String, dynamic> json) =>
|
||||
_$AuthenticateResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$AuthenticateResponseToJson(this);
|
||||
}
|
||||
|
||||
@@ -9,10 +9,17 @@ class GetHolidays extends WebuntisApi {
|
||||
@override
|
||||
Future<GetHolidaysResponse> run() async {
|
||||
final rawAnswer = await query(this);
|
||||
return finalize(GetHolidaysResponse.fromJson(jsonDecode(rawAnswer) as Map<String, dynamic>));
|
||||
return finalize(
|
||||
GetHolidaysResponse.fromJson(
|
||||
jsonDecode(rawAnswer) as Map<String, dynamic>,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static GetHolidaysResponseObject? find(GetHolidaysResponse holidaysResponse, {DateTime? time}) {
|
||||
static GetHolidaysResponseObject? find(
|
||||
GetHolidaysResponse holidaysResponse, {
|
||||
DateTime? time,
|
||||
}) {
|
||||
time ??= DateTime.now();
|
||||
time = DateTime(time.year, time.month, time.day, 0, 0, 0, 0, 0);
|
||||
|
||||
@@ -20,9 +27,8 @@ class GetHolidays extends WebuntisApi {
|
||||
var start = DateTime.parse(element.startDate.toString());
|
||||
var end = DateTime.parse(element.endDate.toString());
|
||||
|
||||
if(!start.isAfter(time) && !end.isBefore(time)) return element;
|
||||
if (!start.isAfter(time) && !end.isBefore(time)) return element;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ import 'get_holidays_response.dart';
|
||||
|
||||
class GetHolidaysCache extends SimpleCache<GetHolidaysResponse> {
|
||||
GetHolidaysCache({super.onUpdate, super.onError, super.renew})
|
||||
: super(
|
||||
cacheTime: RequestCache.cacheDay,
|
||||
loader: () => GetHolidays().run(),
|
||||
fromJson: GetHolidaysResponse.fromJson,
|
||||
) {
|
||||
: super(
|
||||
cacheTime: RequestCache.cacheDay,
|
||||
loader: () => GetHolidays().run(),
|
||||
fromJson: GetHolidaysResponse.fromJson,
|
||||
) {
|
||||
start('wu-holidays');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ class GetHolidaysResponse extends ApiResponse {
|
||||
|
||||
GetHolidaysResponse(this.result);
|
||||
|
||||
factory GetHolidaysResponse.fromJson(Map<String, dynamic> json) => _$GetHolidaysResponseFromJson(json);
|
||||
factory GetHolidaysResponse.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetHolidaysResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetHolidaysResponseToJson(this);
|
||||
}
|
||||
|
||||
@@ -22,8 +23,15 @@ class GetHolidaysResponseObject {
|
||||
int startDate;
|
||||
int endDate;
|
||||
|
||||
GetHolidaysResponseObject(this.id, this.name, this.longName, this.startDate, this.endDate);
|
||||
GetHolidaysResponseObject(
|
||||
this.id,
|
||||
this.name,
|
||||
this.longName,
|
||||
this.startDate,
|
||||
this.endDate,
|
||||
);
|
||||
|
||||
factory GetHolidaysResponseObject.fromJson(Map<String, dynamic> json) => _$GetHolidaysResponseObjectFromJson(json);
|
||||
factory GetHolidaysResponseObject.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetHolidaysResponseObjectFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetHolidaysResponseObjectToJson(this);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,11 @@ class GetRooms extends WebuntisApi {
|
||||
Future<GetRoomsResponse> run() async {
|
||||
final rawAnswer = await query(this);
|
||||
try {
|
||||
return finalize(GetRoomsResponse.fromJson(jsonDecode(rawAnswer) as Map<String, dynamic>));
|
||||
return finalize(
|
||||
GetRoomsResponse.fromJson(
|
||||
jsonDecode(rawAnswer) as Map<String, dynamic>,
|
||||
),
|
||||
);
|
||||
} catch (e, trace) {
|
||||
log(trace.toString());
|
||||
log('Failed to parse getRoom data with server response: $rawAnswer');
|
||||
@@ -19,5 +23,4 @@ class GetRooms extends WebuntisApi {
|
||||
|
||||
throw Exception('Failed to parse getRoom server response: $rawAnswer');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ import 'get_rooms_response.dart';
|
||||
|
||||
class GetRoomsCache extends SimpleCache<GetRoomsResponse> {
|
||||
GetRoomsCache({super.onUpdate, super.onError, super.renew})
|
||||
: super(
|
||||
cacheTime: RequestCache.cacheHour,
|
||||
loader: () => GetRooms().run(),
|
||||
fromJson: GetRoomsResponse.fromJson,
|
||||
) {
|
||||
: super(
|
||||
cacheTime: RequestCache.cacheHour,
|
||||
loader: () => GetRooms().run(),
|
||||
fromJson: GetRoomsResponse.fromJson,
|
||||
) {
|
||||
start('wu-rooms');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ class GetRoomsResponse extends ApiResponse {
|
||||
|
||||
GetRoomsResponse(this.result);
|
||||
|
||||
factory GetRoomsResponse.fromJson(Map<String, dynamic> json) => _$GetRoomsResponseFromJson(json);
|
||||
factory GetRoomsResponse.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetRoomsResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetRoomsResponseToJson(this);
|
||||
}
|
||||
|
||||
@@ -22,8 +23,15 @@ class GetRoomsResponseObject {
|
||||
bool active;
|
||||
String building;
|
||||
|
||||
GetRoomsResponseObject(this.id, this.name, this.longName, this.active, this.building);
|
||||
GetRoomsResponseObject(
|
||||
this.id,
|
||||
this.name,
|
||||
this.longName,
|
||||
this.active,
|
||||
this.building,
|
||||
);
|
||||
|
||||
factory GetRoomsResponseObject.fromJson(Map<String, dynamic> json) => _$GetRoomsResponseObjectFromJson(json);
|
||||
factory GetRoomsResponseObject.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetRoomsResponseObjectFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetRoomsResponseObjectToJson(this);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@ class GetSubjects extends WebuntisApi {
|
||||
@override
|
||||
Future<GetSubjectsResponse> run() async {
|
||||
final rawAnswer = await query(this);
|
||||
return finalize(GetSubjectsResponse.fromJson(jsonDecode(rawAnswer) as Map<String, dynamic>));
|
||||
return finalize(
|
||||
GetSubjectsResponse.fromJson(
|
||||
jsonDecode(rawAnswer) as Map<String, dynamic>,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ import 'get_subjects_response.dart';
|
||||
|
||||
class GetSubjectsCache extends SimpleCache<GetSubjectsResponse> {
|
||||
GetSubjectsCache({super.onUpdate, super.onError, super.renew})
|
||||
: super(
|
||||
cacheTime: RequestCache.cacheHour,
|
||||
loader: () => GetSubjects().run(),
|
||||
fromJson: GetSubjectsResponse.fromJson,
|
||||
) {
|
||||
: super(
|
||||
cacheTime: RequestCache.cacheHour,
|
||||
loader: () => GetSubjects().run(),
|
||||
fromJson: GetSubjectsResponse.fromJson,
|
||||
) {
|
||||
start('wu-subjects');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ class GetSubjectsResponse extends ApiResponse {
|
||||
|
||||
GetSubjectsResponse(this.result);
|
||||
|
||||
factory GetSubjectsResponse.fromJson(Map<String, dynamic> json) => _$GetSubjectsResponseFromJson(json);
|
||||
factory GetSubjectsResponse.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetSubjectsResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetSubjectsResponseToJson(this);
|
||||
}
|
||||
|
||||
@@ -22,8 +23,15 @@ class GetSubjectsResponseObject {
|
||||
String alternateName;
|
||||
bool active;
|
||||
|
||||
GetSubjectsResponseObject(this.id, this.name, this.longName, this.alternateName, this.active);
|
||||
GetSubjectsResponseObject(
|
||||
this.id,
|
||||
this.name,
|
||||
this.longName,
|
||||
this.alternateName,
|
||||
this.active,
|
||||
);
|
||||
|
||||
factory GetSubjectsResponseObject.fromJson(Map<String, dynamic> json) => _$GetSubjectsResponseObjectFromJson(json);
|
||||
factory GetSubjectsResponseObject.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetSubjectsResponseObjectFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetSubjectsResponseObjectToJson(this);
|
||||
}
|
||||
|
||||
@@ -11,12 +11,20 @@ class GetTimegridUnits extends WebuntisApi {
|
||||
Future<GetTimegridUnitsResponse> run() async {
|
||||
final rawAnswer = await query(this);
|
||||
try {
|
||||
return finalize(GetTimegridUnitsResponse.fromJson(jsonDecode(rawAnswer) as Map<String, dynamic>));
|
||||
return finalize(
|
||||
GetTimegridUnitsResponse.fromJson(
|
||||
jsonDecode(rawAnswer) as Map<String, dynamic>,
|
||||
),
|
||||
);
|
||||
} catch (e, trace) {
|
||||
log(trace.toString());
|
||||
log('Failed to parse getTimegridUnits data with server response: $rawAnswer');
|
||||
log(
|
||||
'Failed to parse getTimegridUnits data with server response: $rawAnswer',
|
||||
);
|
||||
}
|
||||
|
||||
throw Exception('Failed to parse getTimegridUnits server response: $rawAnswer');
|
||||
throw Exception(
|
||||
'Failed to parse getTimegridUnits server response: $rawAnswer',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ import 'get_timegrid_units_response.dart';
|
||||
|
||||
class GetTimegridUnitsCache extends SimpleCache<GetTimegridUnitsResponse> {
|
||||
GetTimegridUnitsCache({super.onUpdate, super.renew})
|
||||
: super(
|
||||
cacheTime: RequestCache.cacheDay,
|
||||
loader: () => GetTimegridUnits().run(),
|
||||
fromJson: GetTimegridUnitsResponse.fromJson,
|
||||
) {
|
||||
: super(
|
||||
cacheTime: RequestCache.cacheDay,
|
||||
loader: () => GetTimegridUnits().run(),
|
||||
fromJson: GetTimegridUnitsResponse.fromJson,
|
||||
) {
|
||||
start('wu-timegrid');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ class GetTimegridUnitsResponse extends ApiResponse {
|
||||
|
||||
GetTimegridUnitsResponse(this.result);
|
||||
|
||||
factory GetTimegridUnitsResponse.fromJson(Map<String, dynamic> json) => _$GetTimegridUnitsResponseFromJson(json);
|
||||
factory GetTimegridUnitsResponse.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetTimegridUnitsResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetTimegridUnitsResponseToJson(this);
|
||||
}
|
||||
|
||||
@@ -21,7 +22,8 @@ class GetTimegridUnitsResponseDay {
|
||||
|
||||
GetTimegridUnitsResponseDay(this.day, this.timeUnits);
|
||||
|
||||
factory GetTimegridUnitsResponseDay.fromJson(Map<String, dynamic> json) => _$GetTimegridUnitsResponseDayFromJson(json);
|
||||
factory GetTimegridUnitsResponseDay.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetTimegridUnitsResponseDayFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetTimegridUnitsResponseDayToJson(this);
|
||||
}
|
||||
|
||||
@@ -33,6 +35,7 @@ class GetTimegridUnitsResponseUnit {
|
||||
|
||||
GetTimegridUnitsResponseUnit(this.name, this.startTime, this.endTime);
|
||||
|
||||
factory GetTimegridUnitsResponseUnit.fromJson(Map<String, dynamic> json) => _$GetTimegridUnitsResponseUnitFromJson(json);
|
||||
factory GetTimegridUnitsResponseUnit.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetTimegridUnitsResponseUnitFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetTimegridUnitsResponseUnitToJson(this);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,10 @@ class GetTimetable extends WebuntisApi {
|
||||
@override
|
||||
Future<GetTimetableResponse> run() async {
|
||||
final rawAnswer = await query(this);
|
||||
return finalize(GetTimetableResponse.fromJson(jsonDecode(rawAnswer) as Map<String, dynamic>));
|
||||
return finalize(
|
||||
GetTimetableResponse.fromJson(
|
||||
jsonDecode(rawAnswer) as Map<String, dynamic>,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,11 +12,11 @@ class GetTimetableCache extends SimpleCache<GetTimetableResponse> {
|
||||
required int enddate,
|
||||
super.renew,
|
||||
}) : super(
|
||||
cacheTime: RequestCache.cacheMinute,
|
||||
loader: () => _load(startdate, enddate),
|
||||
fromJson: GetTimetableResponse.fromJson,
|
||||
onUpdate: onUpdate,
|
||||
) {
|
||||
cacheTime: RequestCache.cacheMinute,
|
||||
loader: () => _load(startdate, enddate),
|
||||
fromJson: GetTimetableResponse.fromJson,
|
||||
onUpdate: onUpdate,
|
||||
) {
|
||||
start('wu-timetable-$startdate-$enddate');
|
||||
}
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@ class GetTimetableParams extends ApiParams {
|
||||
|
||||
GetTimetableParams({required this.options});
|
||||
|
||||
factory GetTimetableParams.fromJson(Map<String, dynamic> json) => _$GetTimetableParamsFromJson(json);
|
||||
factory GetTimetableParams.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetTimetableParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetTimetableParamsToJson(this);
|
||||
}
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GetTimetableParamsOptions {
|
||||
GetTimetableParamsOptionsElement element;
|
||||
@@ -59,20 +59,30 @@ class GetTimetableParamsOptions {
|
||||
this.klasseFields,
|
||||
this.roomFields,
|
||||
this.subjectFields,
|
||||
this.teacherFields
|
||||
this.teacherFields,
|
||||
});
|
||||
|
||||
factory GetTimetableParamsOptions.fromJson(Map<String, dynamic> json) => _$GetTimetableParamsOptionsFromJson(json);
|
||||
factory GetTimetableParamsOptions.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetTimetableParamsOptionsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetTimetableParamsOptionsToJson(this);
|
||||
}
|
||||
|
||||
enum GetTimetableParamsOptionsFields {
|
||||
@JsonValue('id') id,
|
||||
@JsonValue('name') name,
|
||||
@JsonValue('longname') longname,
|
||||
@JsonValue('externalkey') externalkey;
|
||||
@JsonValue('id')
|
||||
id,
|
||||
@JsonValue('name')
|
||||
name,
|
||||
@JsonValue('longname')
|
||||
longname,
|
||||
@JsonValue('externalkey')
|
||||
externalkey;
|
||||
|
||||
static List<GetTimetableParamsOptionsFields> all = [id, name, longname, externalkey];
|
||||
static List<GetTimetableParamsOptionsFields> all = [
|
||||
id,
|
||||
name,
|
||||
longname,
|
||||
externalkey,
|
||||
];
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
@@ -82,13 +92,23 @@ class GetTimetableParamsOptionsElement {
|
||||
@JsonKey(includeIfNull: false)
|
||||
GetTimetableParamsOptionsElementKeyType? keyType;
|
||||
|
||||
GetTimetableParamsOptionsElement({required this.id, required this.type, this.keyType});
|
||||
factory GetTimetableParamsOptionsElement.fromJson(Map<String, dynamic> json) => _$GetTimetableParamsOptionsElementFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetTimetableParamsOptionsElementToJson(this);
|
||||
GetTimetableParamsOptionsElement({
|
||||
required this.id,
|
||||
required this.type,
|
||||
this.keyType,
|
||||
});
|
||||
factory GetTimetableParamsOptionsElement.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _$GetTimetableParamsOptionsElementFromJson(json);
|
||||
Map<String, dynamic> toJson() =>
|
||||
_$GetTimetableParamsOptionsElementToJson(this);
|
||||
}
|
||||
|
||||
enum GetTimetableParamsOptionsElementKeyType {
|
||||
@JsonValue('id') id,
|
||||
@JsonValue('name') name,
|
||||
@JsonValue('externalkey') externalkey
|
||||
@JsonValue('id')
|
||||
id,
|
||||
@JsonValue('name')
|
||||
name,
|
||||
@JsonValue('externalkey')
|
||||
externalkey,
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ class GetTimetableResponse extends ApiResponse {
|
||||
|
||||
GetTimetableResponse(this.result);
|
||||
|
||||
factory GetTimetableResponse.fromJson(Map<String, dynamic> json) => _$GetTimetableResponseFromJson(json);
|
||||
factory GetTimetableResponse.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetTimetableResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetTimetableResponseToJson(this);
|
||||
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
@@ -55,10 +55,11 @@ class GetTimetableResponseObject {
|
||||
required this.kl,
|
||||
required this.te,
|
||||
required this.su,
|
||||
required this.ro
|
||||
required this.ro,
|
||||
});
|
||||
|
||||
factory GetTimetableResponseObject.fromJson(Map<String, dynamic> json) => _$GetTimetableResponseObjectFromJson(json);
|
||||
factory GetTimetableResponseObject.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetTimetableResponseObjectFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetTimetableResponseObjectToJson(this);
|
||||
}
|
||||
|
||||
@@ -68,8 +69,11 @@ class GetTimetableResponseObjectFields {
|
||||
|
||||
GetTimetableResponseObjectFields(this.te);
|
||||
|
||||
factory GetTimetableResponseObjectFields.fromJson(Map<String, dynamic> json) => _$GetTimetableResponseObjectFieldsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetTimetableResponseObjectFieldsToJson(this);
|
||||
factory GetTimetableResponseObjectFields.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _$GetTimetableResponseObjectFieldsFromJson(json);
|
||||
Map<String, dynamic> toJson() =>
|
||||
_$GetTimetableResponseObjectFieldsToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
@@ -79,10 +83,18 @@ class GetTimetableResponseObjectFieldsObject {
|
||||
String? longname;
|
||||
String? externalkey;
|
||||
|
||||
GetTimetableResponseObjectFieldsObject({this.id, this.name, this.longname, this.externalkey});
|
||||
GetTimetableResponseObjectFieldsObject({
|
||||
this.id,
|
||||
this.name,
|
||||
this.longname,
|
||||
this.externalkey,
|
||||
});
|
||||
|
||||
factory GetTimetableResponseObjectFieldsObject.fromJson(Map<String, dynamic> json) => _$GetTimetableResponseObjectFieldsObjectFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetTimetableResponseObjectFieldsObjectToJson(this);
|
||||
factory GetTimetableResponseObjectFieldsObject.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _$GetTimetableResponseObjectFieldsObjectFromJson(json);
|
||||
Map<String, dynamic> toJson() =>
|
||||
_$GetTimetableResponseObjectFieldsObjectToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
@@ -92,10 +104,17 @@ class GetTimetableResponseObjectClass {
|
||||
String longname;
|
||||
String? externalkey;
|
||||
|
||||
GetTimetableResponseObjectClass(this.id, this.name, this.longname, this.externalkey);
|
||||
GetTimetableResponseObjectClass(
|
||||
this.id,
|
||||
this.name,
|
||||
this.longname,
|
||||
this.externalkey,
|
||||
);
|
||||
|
||||
factory GetTimetableResponseObjectClass.fromJson(Map<String, dynamic> json) => _$GetTimetableResponseObjectClassFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetTimetableResponseObjectClassToJson(this);
|
||||
factory GetTimetableResponseObjectClass.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetTimetableResponseObjectClassFromJson(json);
|
||||
Map<String, dynamic> toJson() =>
|
||||
_$GetTimetableResponseObjectClassToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
@@ -107,11 +126,20 @@ class GetTimetableResponseObjectTeacher {
|
||||
String? orgname;
|
||||
String? externalkey;
|
||||
|
||||
GetTimetableResponseObjectTeacher(
|
||||
this.id,
|
||||
this.name,
|
||||
this.longname,
|
||||
this.orgid,
|
||||
this.orgname,
|
||||
this.externalkey,
|
||||
);
|
||||
|
||||
GetTimetableResponseObjectTeacher(this.id, this.name, this.longname, this.orgid, this.orgname, this.externalkey);
|
||||
|
||||
factory GetTimetableResponseObjectTeacher.fromJson(Map<String, dynamic> json) => _$GetTimetableResponseObjectTeacherFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetTimetableResponseObjectTeacherToJson(this);
|
||||
factory GetTimetableResponseObjectTeacher.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _$GetTimetableResponseObjectTeacherFromJson(json);
|
||||
Map<String, dynamic> toJson() =>
|
||||
_$GetTimetableResponseObjectTeacherToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
@@ -122,8 +150,11 @@ class GetTimetableResponseObjectSubject {
|
||||
|
||||
GetTimetableResponseObjectSubject(this.id, this.name, this.longname);
|
||||
|
||||
factory GetTimetableResponseObjectSubject.fromJson(Map<String, dynamic> json) => _$GetTimetableResponseObjectSubjectFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetTimetableResponseObjectSubjectToJson(this);
|
||||
factory GetTimetableResponseObjectSubject.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _$GetTimetableResponseObjectSubjectFromJson(json);
|
||||
Map<String, dynamic> toJson() =>
|
||||
_$GetTimetableResponseObjectSubjectToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
@@ -134,6 +165,7 @@ class GetTimetableResponseObjectRoom {
|
||||
|
||||
GetTimetableResponseObjectRoom(this.id, this.name, this.longname);
|
||||
|
||||
factory GetTimetableResponseObjectRoom.fromJson(Map<String, dynamic> json) => _$GetTimetableResponseObjectRoomFromJson(json);
|
||||
factory GetTimetableResponseObjectRoom.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetTimetableResponseObjectRoomFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetTimetableResponseObjectRoomToJson(this);
|
||||
}
|
||||
|
||||
@@ -9,10 +9,14 @@ import '../queries/get_subjects/get_subjects_response.dart';
|
||||
/// When a record is missing the resolver returns a placeholder fallback
|
||||
/// instead of `null` so call sites stay branch-free.
|
||||
class LessonResolver {
|
||||
static GetSubjectsResponseObject resolveSubject(TimetableState state, int? id) {
|
||||
static GetSubjectsResponseObject resolveSubject(
|
||||
TimetableState state,
|
||||
int? id,
|
||||
) {
|
||||
final fallback = GetSubjectsResponseObject(0, '?', 'Unbekannt', '?', true);
|
||||
if (id == null) return fallback;
|
||||
return state.subjects?.result.firstWhereOrNull((s) => s.id == id) ?? fallback;
|
||||
return state.subjects?.result.firstWhereOrNull((s) => s.id == id) ??
|
||||
fallback;
|
||||
}
|
||||
|
||||
static GetRoomsResponseObject resolveRoom(TimetableState state, int? id) {
|
||||
@@ -61,9 +65,7 @@ class LessonFormatter {
|
||||
/// optional longname (rendered in parentheses if it differs from `name`),
|
||||
/// and optional extra info (joined with `·`).
|
||||
static String formatLine(String name, {String? longname, String? extra}) {
|
||||
final parts = <String>[
|
||||
if (name.isNotEmpty) name else '?',
|
||||
];
|
||||
final parts = <String>[if (name.isNotEmpty) name else '?'];
|
||||
final ln = (longname ?? '').trim();
|
||||
if (ln.isNotEmpty && ln != name) parts.add('($ln)');
|
||||
final ex = (extra ?? '').trim();
|
||||
|
||||
@@ -14,18 +14,24 @@ import 'queries/authenticate/authenticate.dart';
|
||||
import 'webuntis_error.dart';
|
||||
|
||||
abstract class WebuntisApi extends ApiRequest {
|
||||
Uri endpoint = Uri.parse('https://${EndpointData().webuntis().full()}/WebUntis/jsonrpc.do?school=marianum-fulda');
|
||||
Uri endpoint = Uri.parse(
|
||||
'https://${EndpointData().webuntis().full()}/WebUntis/jsonrpc.do?school=marianum-fulda',
|
||||
);
|
||||
String method;
|
||||
ApiParams? genericParam;
|
||||
http.Response? response;
|
||||
|
||||
bool authenticatedResponse;
|
||||
|
||||
WebuntisApi(this.method, this.genericParam, {this.authenticatedResponse = true});
|
||||
|
||||
WebuntisApi(
|
||||
this.method,
|
||||
this.genericParam, {
|
||||
this.authenticatedResponse = true,
|
||||
});
|
||||
|
||||
Future<String> query(WebuntisApi untis, {bool retry = false}) async {
|
||||
final body = '{"id":"ID","method":"$method","params":${untis._body()},"jsonrpc":"2.0"}';
|
||||
final body =
|
||||
'{"id":"ID","method":"$method","params":${untis._body()},"jsonrpc":"2.0"}';
|
||||
|
||||
var sessionId = '0';
|
||||
if (authenticatedResponse) {
|
||||
@@ -38,13 +44,20 @@ abstract class WebuntisApi extends ApiRequest {
|
||||
try {
|
||||
jsonData = jsonDecode(data.body) as Map<String, dynamic>;
|
||||
} on FormatException catch (e) {
|
||||
throw ParseException(technicalDetails: 'WebUntis JSON decode: ${e.message}');
|
||||
throw ParseException(
|
||||
technicalDetails: 'WebUntis JSON decode: ${e.message}',
|
||||
);
|
||||
}
|
||||
final error = jsonData['error'] as Map<String, dynamic>?;
|
||||
if (error != null) {
|
||||
final code = error['code'] as int;
|
||||
if (code == -8520) {
|
||||
if (retry) throw WebuntisError('Authentication was tried (probably session timeout), but was not successful!', -8520);
|
||||
if (retry) {
|
||||
throw WebuntisError(
|
||||
'Authentication was tried (probably session timeout), but was not successful!',
|
||||
-8520,
|
||||
);
|
||||
}
|
||||
await Authenticate.createSession();
|
||||
return query(untis, retry: true);
|
||||
} else {
|
||||
@@ -65,14 +78,22 @@ abstract class WebuntisApi extends ApiRequest {
|
||||
|
||||
Future<http.Response> post(String data, Map<String, String>? headers) async {
|
||||
try {
|
||||
return await http.post(endpoint, body: data, headers: headers).timeout(
|
||||
return await http
|
||||
.post(endpoint, body: data, headers: headers)
|
||||
.timeout(
|
||||
const Duration(seconds: 10),
|
||||
onTimeout: () => throw NetworkException.timeout(technicalDetails: 'WebUntis $method timed out after 10s'),
|
||||
onTimeout: () => throw NetworkException.timeout(
|
||||
technicalDetails: 'WebUntis $method timed out after 10s',
|
||||
),
|
||||
);
|
||||
} on SocketException catch (e) {
|
||||
throw NetworkException(technicalDetails: 'WebUntis $method: ${e.message}');
|
||||
throw NetworkException(
|
||||
technicalDetails: 'WebUntis $method: ${e.message}',
|
||||
);
|
||||
} on http.ClientException catch (e) {
|
||||
throw NetworkException(technicalDetails: 'WebUntis $method: ${e.message}');
|
||||
throw NetworkException(
|
||||
technicalDetails: 'WebUntis $method: ${e.message}',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user