Added api for sending feedback
This commit is contained in:
parent
da28a13268
commit
3681fcdae0
@ -1,5 +1,4 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:developer';
|
|
||||||
|
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import '../apiError.dart';
|
import '../apiError.dart';
|
||||||
@ -23,7 +22,7 @@ abstract class MhslApi<T> extends ApiRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(data.statusCode > 299) {
|
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));
|
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:convert';
|
||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:crypto/crypto.dart';
|
|
||||||
import 'package:device_info_plus/device_info_plus.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:http/http.dart' as http;
|
||||||
import 'package:package_info/package_info.dart';
|
import 'package:package_info/package_info.dart';
|
||||||
|
|
||||||
@ -21,18 +19,17 @@ class UpdateUserIndex extends MhslApi<void> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<http.Response> request(Uri uri) {
|
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 {
|
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(
|
UpdateUserIndex(
|
||||||
UpdateUserIndexParams(
|
UpdateUserIndexParams(
|
||||||
username: AccountData().getUsername(),
|
username: AccountData().getUsername(),
|
||||||
user: userId,
|
user: AccountData().getUserId(),
|
||||||
device: deviceId,
|
device: await AccountData().getDeviceId(),
|
||||||
appVersion: int.parse((await PackageInfo.fromPlatform()).buildNumber),
|
appVersion: int.parse((await PackageInfo.fromPlatform()).buildNumber),
|
||||||
deviceInfo: jsonEncode((await DeviceInfoPlugin().deviceInfo).data).toString(),
|
deviceInfo: jsonEncode((await DeviceInfoPlugin().deviceInfo).data).toString(),
|
||||||
),
|
),
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:crypto/crypto.dart';
|
||||||
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
@ -35,6 +38,14 @@ class AccountData {
|
|||||||
return _password!;
|
return _password!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getUserId() {
|
||||||
|
return sha512.convert(utf8.encode("${AccountData().getUsername()}:${AccountData().getPassword()}")).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<String> getDeviceId() async {
|
||||||
|
return sha512.convert(utf8.encode("${getUserId()}@${await FirebaseMessaging.instance.getToken()}")).toString();
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> setData(String username, String password) async {
|
Future<void> setData(String username, String password) async {
|
||||||
SharedPreferences storage = await _storage;
|
SharedPreferences storage = await _storage;
|
||||||
|
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:marianum_mobile/api/mhsl/server/feedback/addFeedback.dart';
|
||||||
|
import 'package:marianum_mobile/api/mhsl/server/feedback/addFeedbackParams.dart';
|
||||||
|
import 'package:marianum_mobile/model/accountData.dart';
|
||||||
|
import 'package:package_info/package_info.dart';
|
||||||
|
|
||||||
class FeedbackDialog extends StatefulWidget {
|
class FeedbackDialog extends StatefulWidget {
|
||||||
const FeedbackDialog({super.key});
|
const FeedbackDialog({super.key});
|
||||||
@ -9,21 +13,25 @@ class FeedbackDialog extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _FeedbackDialogState extends State<FeedbackDialog> {
|
class _FeedbackDialogState extends State<FeedbackDialog> {
|
||||||
|
final TextEditingController _feedbackInput = TextEditingController();
|
||||||
|
String? _error;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
|
|
||||||
title: const Text("Feedback"),
|
title: const Text("Feedback"),
|
||||||
content: const Column(
|
content: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text("Feedback, Anregungen, Ideen, Fehler und Verbesserungen"),
|
const Text("Feedback, Anregungen, Ideen, Fehler und Verbesserungen"),
|
||||||
SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
Text("Bitte gib keine geheimen Daten wie z.B. Passwörter weiter.", style: TextStyle(fontSize: 10)),
|
const Text("Bitte gib keine geheimen Daten wie z.B. Passwörter weiter.", style: TextStyle(fontSize: 10)),
|
||||||
SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
TextField(
|
TextField(
|
||||||
|
controller: _feedbackInput,
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
decoration: InputDecoration(
|
decoration: const InputDecoration(
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
label: Text("Feedback und Verbesserungen")
|
label: Text("Feedback und Verbesserungen")
|
||||||
),
|
),
|
||||||
@ -31,14 +39,31 @@ class _FeedbackDialogState extends State<FeedbackDialog> {
|
|||||||
// expands: true,
|
// expands: true,
|
||||||
minLines: 3,
|
minLines: 3,
|
||||||
maxLines: 5,
|
maxLines: 5,
|
||||||
|
),
|
||||||
|
Visibility(
|
||||||
|
visible: _error != null,
|
||||||
|
child: Text("Senden fehlgeschlagen: $_error", style: const TextStyle(color: Colors.red))
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(onPressed: () => Navigator.of(context).pop(), child: const Text("Abbrechen")),
|
TextButton(onPressed: () => Navigator.of(context).pop(), child: const Text("Abbrechen")),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
|
AddFeedback(
|
||||||
|
AddFeedbackParams(
|
||||||
|
user: AccountData().getUserId(),
|
||||||
|
feedback: _feedbackInput.text,
|
||||||
|
appVersion: int.parse((await PackageInfo.fromPlatform()).buildNumber)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.run()
|
||||||
|
.then((value) => Navigator.of(context).pop())
|
||||||
|
.catchError((error, trace) {
|
||||||
|
setState(() {
|
||||||
|
_error = error.toString();
|
||||||
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
child: const Text("Senden"),
|
child: const Text("Senden"),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user