Implement Webuntis HTTP Api and Display
This commit is contained in:
16
lib/api/webuntis/queries/getSubjects/getSubjects.dart
Normal file
16
lib/api/webuntis/queries/getSubjects/getSubjects.dart
Normal 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)));
|
||||
}
|
||||
}
|
23
lib/api/webuntis/queries/getSubjects/getSubjectsCache.dart
Normal file
23
lib/api/webuntis/queries/getSubjects/getSubjectsCache.dart
Normal 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));
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
@ -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,
|
||||
};
|
Reference in New Issue
Block a user