Added api for custom timetable events
This commit is contained in:
@ -0,0 +1,23 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../mhslApi.dart';
|
||||
import 'getCustomTimetableEventParams.dart';
|
||||
import 'getCustomTimetableEventResponse.dart';
|
||||
|
||||
class GetCustomTimetableEvent extends MhslApi<GetCustomTimetableEventResponse> {
|
||||
GetCustomTimetableEventParams params;
|
||||
GetCustomTimetableEvent(this.params) : super("server/timetable/customEvents?user=${params.user}");
|
||||
|
||||
@override
|
||||
GetCustomTimetableEventResponse assemble(String raw) {
|
||||
return GetCustomTimetableEventResponse.fromJson({"events": jsonDecode(raw)});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri) {
|
||||
return http.get(uri);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import '../../../requestCache.dart';
|
||||
import 'getCustomTimetableEvent.dart';
|
||||
import 'getCustomTimetableEventParams.dart';
|
||||
import 'getCustomTimetableEventResponse.dart';
|
||||
|
||||
class GetCustomTimetableEventCache extends RequestCache<GetCustomTimetableEventResponse> {
|
||||
GetCustomTimetableEventParams params;
|
||||
|
||||
GetCustomTimetableEventCache(this.params, {onUpdate, renew}) : super(RequestCache.cacheMinute, onUpdate, renew: renew) {
|
||||
start("MarianumMobile", "customTimetableEvents");
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GetCustomTimetableEventResponse> onLoad() {
|
||||
return GetCustomTimetableEvent(params).run();
|
||||
}
|
||||
|
||||
@override
|
||||
GetCustomTimetableEventResponse onLocalData(String json) {
|
||||
return GetCustomTimetableEventResponse.fromJson(jsonDecode(json));
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'getCustomTimetableEventParams.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class GetCustomTimetableEventParams {
|
||||
String user;
|
||||
|
||||
GetCustomTimetableEventParams(this.user);
|
||||
|
||||
factory GetCustomTimetableEventParams.fromJson(Map<String, dynamic> json) => _$GetCustomTimetableEventParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetCustomTimetableEventParamsToJson(this);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'getCustomTimetableEventParams.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
GetCustomTimetableEventParams _$GetCustomTimetableEventParamsFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
GetCustomTimetableEventParams(
|
||||
json['user'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetCustomTimetableEventParamsToJson(
|
||||
GetCustomTimetableEventParams instance) =>
|
||||
<String, dynamic>{
|
||||
'user': instance.user,
|
||||
};
|
@ -0,0 +1,16 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../../../apiResponse.dart';
|
||||
import '../customTimetableEvent.dart';
|
||||
|
||||
part 'getCustomTimetableEventResponse.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class GetCustomTimetableEventResponse extends ApiResponse {
|
||||
List<CustomTimetableEvent> events;
|
||||
|
||||
GetCustomTimetableEventResponse(this.events);
|
||||
|
||||
factory GetCustomTimetableEventResponse.fromJson(Map<String, dynamic> json) => _$GetCustomTimetableEventResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetCustomTimetableEventResponseToJson(this);
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'getCustomTimetableEventResponse.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
GetCustomTimetableEventResponse _$GetCustomTimetableEventResponseFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
GetCustomTimetableEventResponse(
|
||||
(json['events'] as List<dynamic>)
|
||||
.map((e) => CustomTimetableEvent.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetCustomTimetableEventResponseToJson(
|
||||
GetCustomTimetableEventResponse instance) =>
|
||||
<String, dynamic>{
|
||||
'events': instance.events,
|
||||
};
|
Reference in New Issue
Block a user