Added getHolidays.dart webuntis method
This commit is contained in:
parent
2b6dc8e3e6
commit
e54ae9c2ff
17
lib/api/webuntis/queries/getHolidays/getHolidays.dart
Normal file
17
lib/api/webuntis/queries/getHolidays/getHolidays.dart
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:marianum_mobile/api/webuntis/apiResponse.dart';
|
||||||
|
import 'package:marianum_mobile/api/webuntis/webuntisApi.dart';
|
||||||
|
|
||||||
|
import 'getHolidaysResponse.dart';
|
||||||
|
|
||||||
|
class GetHolidays extends WebuntisApi {
|
||||||
|
GetHolidays() : super("getHolidays", null);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<GetHolidaysResponse> run() async {
|
||||||
|
String rawAnswer = await query(this);
|
||||||
|
return finalize(GetHolidaysResponse.fromJson(jsonDecode(rawAnswer)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
21
lib/api/webuntis/queries/getHolidays/getHolidaysCache.dart
Normal file
21
lib/api/webuntis/queries/getHolidays/getHolidaysCache.dart
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:marianum_mobile/api/requestCache.dart';
|
||||||
|
import 'package:marianum_mobile/api/webuntis/queries/getHolidays/getHolidays.dart';
|
||||||
|
import 'package:marianum_mobile/api/webuntis/queries/getHolidays/getHolidaysResponse.dart';
|
||||||
|
|
||||||
|
class GetHolidaysCache extends RequestCache<GetHolidaysResponse> {
|
||||||
|
GetHolidaysCache({onUpdate}) : super(60 * 60, onUpdate) {
|
||||||
|
start("holidays", "data");
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<GetHolidaysResponse> onLoad() {
|
||||||
|
return GetHolidays().run();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
GetHolidaysResponse onLocalData(String json) {
|
||||||
|
return GetHolidaysResponse.fromJson(jsonDecode(json));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
import 'package:marianum_mobile/api/webuntis/apiResponse.dart';
|
||||||
|
|
||||||
|
part 'getHolidaysResponse.g.dart';
|
||||||
|
|
||||||
|
@JsonSerializable(explicitToJson: true)
|
||||||
|
class GetHolidaysResponse extends ApiResponse {
|
||||||
|
Set<GetHolidaysResponseObject> result;
|
||||||
|
|
||||||
|
GetHolidaysResponse(this.result);
|
||||||
|
|
||||||
|
factory GetHolidaysResponse.fromJson(Map<String, dynamic> json) => _$GetHolidaysResponseFromJson(json);
|
||||||
|
Map<String, dynamic> toJson() => _$GetHolidaysResponseToJson(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonSerializable(explicitToJson: true)
|
||||||
|
class GetHolidaysResponseObject {
|
||||||
|
int id;
|
||||||
|
String name;
|
||||||
|
String longName;
|
||||||
|
int startDate;
|
||||||
|
int endDate;
|
||||||
|
|
||||||
|
GetHolidaysResponseObject(this.id, this.name, this.longName, this.startDate, this.endDate);
|
||||||
|
|
||||||
|
factory GetHolidaysResponseObject.fromJson(Map<String, dynamic> json) => _$GetHolidaysResponseObjectFromJson(json);
|
||||||
|
Map<String, dynamic> toJson() => _$GetHolidaysResponseObjectToJson(this);
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'getHolidaysResponse.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// JsonSerializableGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
GetHolidaysResponse _$GetHolidaysResponseFromJson(Map<String, dynamic> json) =>
|
||||||
|
GetHolidaysResponse(
|
||||||
|
(json['result'] as List<dynamic>)
|
||||||
|
.map((e) =>
|
||||||
|
GetHolidaysResponseObject.fromJson(e as Map<String, dynamic>))
|
||||||
|
.toSet(),
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$GetHolidaysResponseToJson(
|
||||||
|
GetHolidaysResponse instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'result': instance.result.map((e) => e.toJson()).toList(),
|
||||||
|
};
|
||||||
|
|
||||||
|
GetHolidaysResponseObject _$GetHolidaysResponseObjectFromJson(
|
||||||
|
Map<String, dynamic> json) =>
|
||||||
|
GetHolidaysResponseObject(
|
||||||
|
json['id'] as int,
|
||||||
|
json['name'] as String,
|
||||||
|
json['longName'] as String,
|
||||||
|
json['startDate'] as int,
|
||||||
|
json['endDate'] as int,
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$GetHolidaysResponseObjectToJson(
|
||||||
|
GetHolidaysResponseObject instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'id': instance.id,
|
||||||
|
'name': instance.name,
|
||||||
|
'longName': instance.longName,
|
||||||
|
'startDate': instance.startDate,
|
||||||
|
'endDate': instance.endDate,
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user