adopt MarianumConnectQuery base in remaining queries
This commit is contained in:
@@ -3,46 +3,37 @@ import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
import '../../errors/marianumconnect_error.dart';
|
||||
import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import '../../marianumconnect_query.dart';
|
||||
|
||||
/// Submits user feedback to MarianumConnect (`POST me/feedback`, bearer-auth).
|
||||
/// The optional screenshot is sent base64-encoded. Replaces the legacy mhsl.eu
|
||||
/// `server/feedback` endpoint — the user no longer needs to be sent explicitly,
|
||||
/// the bearer token identifies them.
|
||||
class SubmitFeedback {
|
||||
final Dio _dio;
|
||||
|
||||
SubmitFeedback({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
class SubmitFeedback extends MarianumConnectQuery {
|
||||
SubmitFeedback({super.dio});
|
||||
|
||||
Future<void> run({
|
||||
required String message,
|
||||
Uint8List? screenshot,
|
||||
String screenshotContentType = 'image/png',
|
||||
}) async {
|
||||
try {
|
||||
final package = await PackageInfo.fromPlatform();
|
||||
final screenshotBase64 = screenshot != null ? base64Encode(screenshot) : null;
|
||||
await _dio.post<void>(
|
||||
MarianumConnectEndpoint.resolve('me/feedback'),
|
||||
data: {
|
||||
'message': message,
|
||||
'screenshot': ?screenshotBase64,
|
||||
'screenshotContentType': screenshot != null ? screenshotContentType : null,
|
||||
'platform': _platform(),
|
||||
'appVersion': package.version,
|
||||
'appBuild': int.tryParse(package.buildNumber),
|
||||
'deviceModel': await _deviceModel(),
|
||||
},
|
||||
);
|
||||
} on DioException catch (e) {
|
||||
throw mapMarianumConnectError(e);
|
||||
}
|
||||
}
|
||||
}) => guard(() async {
|
||||
final package = await PackageInfo.fromPlatform();
|
||||
final screenshotBase64 = screenshot != null ? base64Encode(screenshot) : null;
|
||||
await dio.post<void>(
|
||||
endpoint('me/feedback'),
|
||||
data: {
|
||||
'message': message,
|
||||
'screenshot': ?screenshotBase64,
|
||||
'screenshotContentType': screenshot != null ? screenshotContentType : null,
|
||||
'platform': _platform(),
|
||||
'appVersion': package.version,
|
||||
'appBuild': int.tryParse(package.buildNumber),
|
||||
'deviceModel': await _deviceModel(),
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
static String? _platform() {
|
||||
if (Platform.isAndroid) return 'android';
|
||||
|
||||
Reference in New Issue
Block a user