Added api for sending feedback

This commit is contained in:
2024-02-09 16:35:47 +01:00
parent da28a13268
commit 3681fcdae0
7 changed files with 112 additions and 18 deletions

View File

@ -0,0 +1,21 @@
import 'dart:convert';
import 'package:http/http.dart';
import 'package:marianum_mobile/api/mhsl/mhslApi.dart';
import 'package:http/http.dart' as http;
import 'addFeedbackParams.dart';
class AddFeedback extends MhslApi<void> {
AddFeedbackParams params;
AddFeedback(this.params) : super('server/feedback');
@override
void assemble(String raw) {}
@override
Future<Response>? request(Uri uri) {
return http.post(uri, body: jsonEncode(params.toJson()));
}
}

View File

@ -0,0 +1,20 @@
import 'package:json_annotation/json_annotation.dart';
part 'addFeedbackParams.g.dart';
@JsonSerializable()
class AddFeedbackParams {
String user;
String feedback;
int appVersion;
AddFeedbackParams({
required this.user,
required this.feedback,
required this.appVersion,
});
factory AddFeedbackParams.fromJson(Map<String, dynamic> json) => _$AddFeedbackParamsFromJson(json);
Map<String, dynamic> toJson() => _$AddFeedbackParamsToJson(this);
}

View File

@ -0,0 +1,21 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'addFeedbackParams.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
AddFeedbackParams _$AddFeedbackParamsFromJson(Map<String, dynamic> json) =>
AddFeedbackParams(
user: json['user'] as String,
feedback: json['feedback'] as String,
appVersion: json['appVersion'] as int,
);
Map<String, dynamic> _$AddFeedbackParamsToJson(AddFeedbackParams instance) =>
<String, dynamic>{
'user': instance.user,
'feedback': instance.feedback,
'appVersion': instance.appVersion,
};

View File

@ -2,9 +2,7 @@
import 'dart:convert';
import 'dart:developer';
import 'package:crypto/crypto.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:http/http.dart' as http;
import 'package:package_info/package_info.dart';
@ -21,18 +19,17 @@ class UpdateUserIndex extends MhslApi<void> {
@override
Future<http.Response> request(Uri uri) {
return http.post(uri, body: jsonEncode(params.toJson()));
String data = jsonEncode(params.toJson());
log("Updating userindex:\n $data");
return http.post(uri, body: data);
}
static void index() async {
String userId = sha512.convert(utf8.encode("${AccountData().getUsername()}:${AccountData().getPassword()}")).toString();
String deviceId = sha512.convert(utf8.encode("$userId@${await FirebaseMessaging.instance.getToken()}")).toString();
log("Userindex:\n userid:$userId\n deviceid:$deviceId");
UpdateUserIndex(
UpdateUserIndexParams(
username: AccountData().getUsername(),
user: userId,
device: deviceId,
user: AccountData().getUserId(),
device: await AccountData().getDeviceId(),
appVersion: int.parse((await PackageInfo.fromPlatform()).buildNumber),
deviceInfo: jsonEncode((await DeviceInfoPlugin().deviceInfo).data).toString(),
),