migrated timetable integration from WebUntis to the MarianumConnect API, implementing a Dio-based client with bearer token authentication, background session validation, and auto-refresh logic.
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import 'timetable_get_schoolyear_response.dart';
|
||||
|
||||
class TimetableGetSchoolyear {
|
||||
final Dio _dio;
|
||||
|
||||
TimetableGetSchoolyear({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
Future<TimetableGetSchoolyearResponse> run() async {
|
||||
try {
|
||||
final response = await _dio.get<Map<String, dynamic>>(
|
||||
MarianumConnectEndpoint.resolve('timetable/schoolyear'),
|
||||
);
|
||||
return TimetableGetSchoolyearResponse.fromJson(response.data!);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../../../api_response.dart';
|
||||
|
||||
part 'timetable_get_schoolyear_response.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class TimetableGetSchoolyearResponse extends ApiResponse {
|
||||
final int id;
|
||||
final String name;
|
||||
|
||||
@JsonKey(fromJson: _dateFromJson, toJson: _dateToJson)
|
||||
final DateTime startDate;
|
||||
|
||||
@JsonKey(fromJson: _dateFromJson, toJson: _dateToJson)
|
||||
final DateTime endDate;
|
||||
|
||||
TimetableGetSchoolyearResponse({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.startDate,
|
||||
required this.endDate,
|
||||
});
|
||||
|
||||
factory TimetableGetSchoolyearResponse.fromJson(Map<String, dynamic> json) =>
|
||||
_$TimetableGetSchoolyearResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() =>
|
||||
_$TimetableGetSchoolyearResponseToJson(this);
|
||||
|
||||
static DateTime _dateFromJson(String raw) => DateTime.parse(raw);
|
||||
static String _dateToJson(DateTime d) =>
|
||||
'${d.year.toString().padLeft(4, '0')}-${d.month.toString().padLeft(2, '0')}-${d.day.toString().padLeft(2, '0')}';
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'timetable_get_schoolyear_response.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
TimetableGetSchoolyearResponse _$TimetableGetSchoolyearResponseFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) =>
|
||||
TimetableGetSchoolyearResponse(
|
||||
id: (json['id'] as num).toInt(),
|
||||
name: json['name'] as String,
|
||||
startDate: TimetableGetSchoolyearResponse._dateFromJson(
|
||||
json['startDate'] as String,
|
||||
),
|
||||
endDate: TimetableGetSchoolyearResponse._dateFromJson(
|
||||
json['endDate'] as String,
|
||||
),
|
||||
)
|
||||
..headers = (json['headers'] as Map<String, dynamic>?)?.map(
|
||||
(k, e) => MapEntry(k, e as String),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$TimetableGetSchoolyearResponseToJson(
|
||||
TimetableGetSchoolyearResponse instance,
|
||||
) => <String, dynamic>{
|
||||
'headers': ?instance.headers,
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
'startDate': TimetableGetSchoolyearResponse._dateToJson(instance.startDate),
|
||||
'endDate': TimetableGetSchoolyearResponse._dateToJson(instance.endDate),
|
||||
};
|
||||
Reference in New Issue
Block a user