Implemented structure for push Notifications

This commit is contained in:
2023-08-19 17:04:45 +02:00
parent 9c5b04cfc6
commit 1a172d3d86
28 changed files with 567 additions and 46 deletions

View File

@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:developer';
import 'package:http/http.dart' as http;
import '../apiError.dart';
@ -21,6 +22,10 @@ abstract class MhslApi<T> extends ApiRequest {
throw ApiError("Request could not be dispatched!");
}
if(data.statusCode > 299) {
log("Non 200 Status code from mhsl services: $subpath: ${data.statusCode}");
}
return assemble(utf8.decode(data.bodyBytes));
}
}

View File

@ -0,0 +1,26 @@
import 'dart:convert';
import 'dart:developer';
import 'package:http/http.dart' as http;
import '../../mhslApi.dart';
import 'notifyRegisterParams.dart';
class NotifyRegister extends MhslApi<void> {
NotifyRegisterParams params;
NotifyRegister(this.params) : super("notify/register/");
@override
void assemble(String raw) {
}
@override
Future<http.Response> request(Uri uri) {
String requestString = jsonEncode(params.toJson());
log(requestString);
return http.post(uri, body: requestString);
}
}

View File

@ -0,0 +1,19 @@
import 'package:json_annotation/json_annotation.dart';
part 'notifyRegisterParams.g.dart';
@JsonSerializable()
class NotifyRegisterParams {
String username;
String password;
String fcmToken;
NotifyRegisterParams({
required this.username,
required this.password,
required this.fcmToken
});
factory NotifyRegisterParams.fromJson(Map<String, dynamic> json) => _$NotifyRegisterParamsFromJson(json);
Map<String, dynamic> toJson() => _$NotifyRegisterParamsToJson(this);
}

View File

@ -0,0 +1,23 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'notifyRegisterParams.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
NotifyRegisterParams _$NotifyRegisterParamsFromJson(
Map<String, dynamic> json) =>
NotifyRegisterParams(
username: json['username'] as String,
password: json['password'] as String,
fcmToken: json['fcmToken'] as String,
);
Map<String, dynamic> _$NotifyRegisterParamsToJson(
NotifyRegisterParams instance) =>
<String, dynamic>{
'username': instance.username,
'password': instance.password,
'fcmToken': instance.fcmToken,
};