mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 00:05:16 +00:00
Managed to send reports
This commit is contained in:
38
lib/helpers/report_helper.dart
Normal file
38
lib/helpers/report_helper.dart
Normal file
@ -0,0 +1,38 @@
|
||||
import 'package:comunic/enums/report_target_type.dart';
|
||||
import 'package:comunic/models/api_request.dart';
|
||||
import 'package:comunic/models/report_target.dart';
|
||||
import 'package:comunic/models/server_config.dart';
|
||||
|
||||
/// Reports Helper
|
||||
///
|
||||
/// @author Pierre Hubert
|
||||
|
||||
enum ReportResult {
|
||||
Success,
|
||||
ErrorAlreadyReported,
|
||||
Error,
|
||||
}
|
||||
|
||||
class ReportHelper {
|
||||
/// Send a new report to the server
|
||||
static Future<ReportResult> sendReport({
|
||||
required ReportCause cause,
|
||||
required ReportTarget target,
|
||||
required String comment,
|
||||
}) async {
|
||||
final response = await APIRequest.withLogin("reports/create", args: {
|
||||
"cause": cause.id,
|
||||
"target_type": target.type.apiId,
|
||||
"target_id": target.id.toString(),
|
||||
"comment": comment
|
||||
}).exec();
|
||||
|
||||
if (response.isOK) return ReportResult.Success;
|
||||
|
||||
print("Failed to send report: ${response.content}");
|
||||
|
||||
if (response.code == 409) return ReportResult.ErrorAlreadyReported;
|
||||
|
||||
return ReportResult.Error;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user