Added api for sending feedback
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../apiError.dart';
|
||||
@ -23,7 +22,7 @@ abstract class MhslApi<T> extends ApiRequest {
|
||||
}
|
||||
|
||||
if(data.statusCode > 299) {
|
||||
log("Non 200 Status code from mhsl services: $subpath: ${data.statusCode}");
|
||||
throw ApiError("Non 200 Status code from mhsl services: $subpath: ${data.statusCode}");
|
||||
}
|
||||
|
||||
return assemble(utf8.decode(data.bodyBytes));
|
||||
|
21
lib/api/mhsl/server/feedback/addFeedback.dart
Normal file
21
lib/api/mhsl/server/feedback/addFeedback.dart
Normal 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()));
|
||||
}
|
||||
}
|
20
lib/api/mhsl/server/feedback/addFeedbackParams.dart
Normal file
20
lib/api/mhsl/server/feedback/addFeedbackParams.dart
Normal 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);
|
||||
}
|
21
lib/api/mhsl/server/feedback/addFeedbackParams.g.dart
Normal file
21
lib/api/mhsl/server/feedback/addFeedbackParams.g.dart
Normal 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,
|
||||
};
|
@ -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(),
|
||||
),
|
||||
|
Reference in New Issue
Block a user