Implement Webuntis HTTP Api and Display

This commit is contained in:
2023-02-15 20:33:05 +01:00
parent 7432972b3c
commit 2b6dc8e3e6
42 changed files with 746 additions and 287 deletions

View File

@ -0,0 +1,16 @@
import 'dart:convert';
import 'package:marianum_mobile/api/webuntis/webuntisApi.dart';
import '../../apiResponse.dart';
import 'getSubjectsResponse.dart';
class GetSubjects extends WebuntisApi {
GetSubjects() : super("getSubjects", null);
@override
Future<GetSubjectsResponse> run() async {
String rawAnswer = await query(this);
return finalize(GetSubjectsResponse.fromJson(jsonDecode(rawAnswer)));
}
}

View File

@ -0,0 +1,23 @@
import 'dart:convert';
import 'package:marianum_mobile/api/requestCache.dart';
import 'package:marianum_mobile/api/webuntis/queries/getSubjects/getSubjectsResponse.dart';
import 'getSubjects.dart';
class GetSubjectsCache extends RequestCache<GetSubjectsResponse> {
GetSubjectsCache({onUpdate}) : super(60 * 60, onUpdate) {
start("subjects", "data");
}
@override
Future<GetSubjectsResponse> onLoad() {
return GetSubjects().run();
}
@override
onLocalData(String json) {
return GetSubjectsResponse.fromJson(jsonDecode(json));
}
}

View File

@ -0,0 +1,28 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:marianum_mobile/api/webuntis/apiResponse.dart';
part 'getSubjectsResponse.g.dart';
@JsonSerializable(explicitToJson: true)
class GetSubjectsResponse extends ApiResponse {
Set<GetSubjectsResponseObject> result;
GetSubjectsResponse(this.result);
factory GetSubjectsResponse.fromJson(Map<String, dynamic> json) => _$GetSubjectsResponseFromJson(json);
Map<String, dynamic> toJson() => _$GetSubjectsResponseToJson(this);
}
@JsonSerializable(explicitToJson: true)
class GetSubjectsResponseObject {
int id;
String name;
String longName;
String alternateName;
bool active;
GetSubjectsResponseObject(this.id, this.name, this.longName, this.alternateName, this.active);
factory GetSubjectsResponseObject.fromJson(Map<String, dynamic> json) => _$GetSubjectsResponseObjectFromJson(json);
Map<String, dynamic> toJson() => _$GetSubjectsResponseObjectToJson(this);
}

View File

@ -0,0 +1,41 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'getSubjectsResponse.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
GetSubjectsResponse _$GetSubjectsResponseFromJson(Map<String, dynamic> json) =>
GetSubjectsResponse(
(json['result'] as List<dynamic>)
.map((e) =>
GetSubjectsResponseObject.fromJson(e as Map<String, dynamic>))
.toSet(),
);
Map<String, dynamic> _$GetSubjectsResponseToJson(
GetSubjectsResponse instance) =>
<String, dynamic>{
'result': instance.result.map((e) => e.toJson()).toList(),
};
GetSubjectsResponseObject _$GetSubjectsResponseObjectFromJson(
Map<String, dynamic> json) =>
GetSubjectsResponseObject(
json['id'] as int,
json['name'] as String,
json['longName'] as String,
json['alternateName'] as String,
json['active'] as bool,
);
Map<String, dynamic> _$GetSubjectsResponseObjectToJson(
GetSubjectsResponseObject instance) =>
<String, dynamic>{
'id': instance.id,
'name': instance.name,
'longName': instance.longName,
'alternateName': instance.alternateName,
'active': instance.active,
};