Added api for custom timetable events
This commit is contained in:
@ -0,0 +1,24 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:http/http.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../mhslApi.dart';
|
||||
import 'addCustomTimetableEventParams.dart';
|
||||
|
||||
class AddCustomTimetableEvent extends MhslApi<void> {
|
||||
AddCustomTimetableEventParams params;
|
||||
|
||||
AddCustomTimetableEvent(this.params) : super('server/timetable/customEvents');
|
||||
|
||||
@override
|
||||
void assemble(String raw) {}
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri) {
|
||||
String body = jsonEncode(params.toJson());
|
||||
log(body);
|
||||
return http.post(uri, body: body);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../customTimetableEvent.dart';
|
||||
|
||||
part 'addCustomTimetableEventParams.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class AddCustomTimetableEventParams {
|
||||
String user;
|
||||
CustomTimetableEvent event;
|
||||
|
||||
AddCustomTimetableEventParams(this.user, this.event);
|
||||
|
||||
factory AddCustomTimetableEventParams.fromJson(Map<String, dynamic> json) => _$AddCustomTimetableEventParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$AddCustomTimetableEventParamsToJson(this);
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'addCustomTimetableEventParams.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
AddCustomTimetableEventParams _$AddCustomTimetableEventParamsFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
AddCustomTimetableEventParams(
|
||||
json['user'] as String,
|
||||
CustomTimetableEvent.fromJson(json['event'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$AddCustomTimetableEventParamsToJson(
|
||||
AddCustomTimetableEventParams instance) =>
|
||||
<String, dynamic>{
|
||||
'user': instance.user,
|
||||
'event': instance.event.toJson(),
|
||||
};
|
28
lib/api/mhsl/customTimetableEvent/customTimetableEvent.dart
Normal file
28
lib/api/mhsl/customTimetableEvent/customTimetableEvent.dart
Normal file
@ -0,0 +1,28 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../mhslApi.dart';
|
||||
|
||||
part 'customTimetableEvent.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class CustomTimetableEvent {
|
||||
String id;
|
||||
String title;
|
||||
String description;
|
||||
@JsonKey(toJson: MhslApi.dateTimeToJson, fromJson: MhslApi.dateTimeFromJson)
|
||||
DateTime startDate;
|
||||
@JsonKey(toJson: MhslApi.dateTimeToJson, fromJson: MhslApi.dateTimeFromJson)
|
||||
DateTime endDate;
|
||||
String rrule;
|
||||
@JsonKey(toJson: MhslApi.dateTimeToJson, fromJson: MhslApi.dateTimeFromJson)
|
||||
DateTime createdAt;
|
||||
@JsonKey(toJson: MhslApi.dateTimeToJson, fromJson: MhslApi.dateTimeFromJson)
|
||||
DateTime updatedAt;
|
||||
|
||||
CustomTimetableEvent({required this.id, required this.title, required this.description, required this.startDate,
|
||||
required this.endDate, required this.rrule, required this.createdAt, required this.updatedAt});
|
||||
|
||||
|
||||
factory CustomTimetableEvent.fromJson(Map<String, dynamic> json) => _$CustomTimetableEventFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$CustomTimetableEventToJson(this);
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'customTimetableEvent.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
CustomTimetableEvent _$CustomTimetableEventFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
CustomTimetableEvent(
|
||||
id: json['id'] as String,
|
||||
title: json['title'] as String,
|
||||
description: json['description'] as String,
|
||||
startDate: MhslApi.dateTimeFromJson(json['startDate'] as String),
|
||||
endDate: MhslApi.dateTimeFromJson(json['endDate'] as String),
|
||||
rrule: json['rrule'] as String,
|
||||
createdAt: MhslApi.dateTimeFromJson(json['createdAt'] as String),
|
||||
updatedAt: MhslApi.dateTimeFromJson(json['updatedAt'] as String),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$CustomTimetableEventToJson(
|
||||
CustomTimetableEvent instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'title': instance.title,
|
||||
'description': instance.description,
|
||||
'startDate': MhslApi.dateTimeToJson(instance.startDate),
|
||||
'endDate': MhslApi.dateTimeToJson(instance.endDate),
|
||||
'rrule': instance.rrule,
|
||||
'createdAt': MhslApi.dateTimeToJson(instance.createdAt),
|
||||
'updatedAt': MhslApi.dateTimeToJson(instance.updatedAt),
|
||||
};
|
@ -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,
|
||||
};
|
@ -0,0 +1,22 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../mhslApi.dart';
|
||||
import 'removeCustomTimetableEventParams.dart';
|
||||
|
||||
class RemoveCustomTimetableEvent extends MhslApi<void> {
|
||||
RemoveCustomTimetableEventParams params;
|
||||
|
||||
RemoveCustomTimetableEvent(this.params) : super('server/timetable/customEvents');
|
||||
|
||||
@override
|
||||
void assemble(String raw) {}
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri) {
|
||||
return http.delete(uri, body: jsonEncode(params.toJson()));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'removeCustomTimetableEventParams.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class RemoveCustomTimetableEventParams {
|
||||
String id;
|
||||
|
||||
RemoveCustomTimetableEventParams(this.id);
|
||||
|
||||
factory RemoveCustomTimetableEventParams.fromJson(Map<String, dynamic> json) => _$RemoveCustomTimetableEventParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$RemoveCustomTimetableEventParamsToJson(this);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'removeCustomTimetableEventParams.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
RemoveCustomTimetableEventParams _$RemoveCustomTimetableEventParamsFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
RemoveCustomTimetableEventParams(
|
||||
json['id'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$RemoveCustomTimetableEventParamsToJson(
|
||||
RemoveCustomTimetableEventParams instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
};
|
@ -0,0 +1,22 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../mhslApi.dart';
|
||||
import 'updateCustomTimetableEventParams.dart';
|
||||
|
||||
class UpdateCustomTimetableEvent extends MhslApi<void> {
|
||||
UpdateCustomTimetableEventParams params;
|
||||
|
||||
UpdateCustomTimetableEvent(this.params) : super('server/timetable/customEvents');
|
||||
|
||||
@override
|
||||
void assemble(String raw) {}
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri) {
|
||||
return http.patch(uri, body: jsonEncode(params.toJson()));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../customTimetableEvent.dart';
|
||||
|
||||
part 'updateCustomTimetableEventParams.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class UpdateCustomTimetableEventParams {
|
||||
String id;
|
||||
CustomTimetableEvent event;
|
||||
|
||||
UpdateCustomTimetableEventParams(this.id, this.event);
|
||||
|
||||
factory UpdateCustomTimetableEventParams.fromJson(Map<String, dynamic> json) => _$UpdateCustomTimetableEventParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$UpdateCustomTimetableEventParamsToJson(this);
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'updateCustomTimetableEventParams.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
UpdateCustomTimetableEventParams _$UpdateCustomTimetableEventParamsFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
UpdateCustomTimetableEventParams(
|
||||
json['id'] as String,
|
||||
CustomTimetableEvent.fromJson(json['event'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$UpdateCustomTimetableEventParamsToJson(
|
||||
UpdateCustomTimetableEventParams instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'event': instance.event.toJson(),
|
||||
};
|
@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import '../apiError.dart';
|
||||
import '../apiRequest.dart';
|
||||
|
||||
@ -27,4 +28,8 @@ abstract class MhslApi<T> extends ApiRequest {
|
||||
|
||||
return assemble(utf8.decode(data.bodyBytes));
|
||||
}
|
||||
|
||||
static String dateTimeToJson(DateTime time) => Jiffy.parseFromDateTime(time).format(pattern: "yyyy-MM-dd HH:mm:ss");
|
||||
static DateTime dateTimeFromJson(String time) => DateTime.parse(time);
|
||||
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart';
|
||||
import 'package:marianum_mobile/api/mhsl/mhslApi.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../mhslApi.dart';
|
||||
import 'addFeedbackParams.dart';
|
||||
|
||||
|
||||
|
@ -28,7 +28,7 @@ class UpdateUserIndex extends MhslApi<void> {
|
||||
UpdateUserIndex(
|
||||
UpdateUserIndexParams(
|
||||
username: AccountData().getUsername(),
|
||||
user: AccountData().getUserId(),
|
||||
user: AccountData().getUserSecret(),
|
||||
device: await AccountData().getDeviceId(),
|
||||
appVersion: int.parse((await PackageInfo.fromPlatform()).buildNumber),
|
||||
deviceInfo: jsonEncode((await DeviceInfoPlugin().deviceInfo).data).toString(),
|
||||
|
@ -17,7 +17,7 @@ class GetRooms extends WebuntisApi {
|
||||
log("Failed to parse getRoom data with server response: $rawAnswer");
|
||||
}
|
||||
|
||||
throw Exception("Failed to parse getRoom server response");
|
||||
throw Exception("Failed to parse getRoom server response: $rawAnswer");
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user