Added Marianum Message pdf reader and backend

This commit is contained in:
2023-05-30 21:08:11 +02:00
parent ba90556e69
commit d71f0d3339
16 changed files with 343 additions and 12 deletions

View File

@ -0,0 +1,18 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:marianum_mobile/api/mhsl/message/getMessages/getMessagesResponse.dart';
import 'package:marianum_mobile/api/mhsl/message/messageApi.dart';
class GetMessages extends MessageApi<GetMessagesResponse> {
@override
GetMessagesResponse assemble(String raw) {
return GetMessagesResponse.fromJson(jsonDecode(raw));
}
@override
Future<http.Response> request(Uri uri) {
return http.get(uri);
}
}

View File

@ -0,0 +1,22 @@
import 'dart:convert';
import 'package:marianum_mobile/api/mhsl/message/getMessages/getMessagesResponse.dart';
import 'package:marianum_mobile/api/requestCache.dart';
import 'getMessages.dart';
class GetMessagesCache extends RequestCache<GetMessagesResponse> {
GetMessagesCache({onUpdate, renew}) : super(RequestCache.cacheMinute, onUpdate, renew: renew) {
start("MarianumMobile", "message");
}
@override
GetMessagesResponse onLocalData(String json) {
return GetMessagesResponse.fromJson(jsonDecode(json));
}
@override
Future<GetMessagesResponse> onLoad() {
return GetMessages().run();
}
}

View File

@ -0,0 +1,27 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:marianum_mobile/api/apiResponse.dart';
part 'getMessagesResponse.g.dart';
@JsonSerializable(explicitToJson: true)
class GetMessagesResponse extends ApiResponse {
String base;
Set<GetMessagesResponseObject> messages;
GetMessagesResponse(this.base, this.messages);
factory GetMessagesResponse.fromJson(Map<String, dynamic> json) => _$GetMessagesResponseFromJson(json);
Map<String, dynamic> toJson() => _$GetMessagesResponseToJson(this);
}
@JsonSerializable(explicitToJson: true)
class GetMessagesResponseObject {
String name;
String date;
String url;
GetMessagesResponseObject(this.name, this.date, this.url);
factory GetMessagesResponseObject.fromJson(Map<String, dynamic> json) => _$GetMessagesResponseObjectFromJson(json);
Map<String, dynamic> toJson() => _$GetMessagesResponseObjectToJson(this);
}

View File

@ -0,0 +1,39 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'getMessagesResponse.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
GetMessagesResponse _$GetMessagesResponseFromJson(Map<String, dynamic> json) =>
GetMessagesResponse(
json['base'] as String,
(json['messages'] as List<dynamic>)
.map((e) =>
GetMessagesResponseObject.fromJson(e as Map<String, dynamic>))
.toSet(),
);
Map<String, dynamic> _$GetMessagesResponseToJson(
GetMessagesResponse instance) =>
<String, dynamic>{
'base': instance.base,
'messages': instance.messages.map((e) => e.toJson()).toList(),
};
GetMessagesResponseObject _$GetMessagesResponseObjectFromJson(
Map<String, dynamic> json) =>
GetMessagesResponseObject(
json['name'] as String,
json['date'] as String,
json['url'] as String,
);
Map<String, dynamic> _$GetMessagesResponseObjectToJson(
GetMessagesResponseObject instance) =>
<String, dynamic>{
'name': instance.name,
'date': instance.date,
'url': instance.url,
};