now sends username in Sent field. hopefully

This commit is contained in:
Nico
2025-06-18 15:28:05 +02:00
parent ce70e4a718
commit d1d5761b0a
3 changed files with 13 additions and 3 deletions

View File

@@ -16,7 +16,7 @@ class HttpRequestService {
/// Send data to the appropriate backend endpoint
/// @param saveDataMap Optional map of data to send
/// @param saveDataString Optional string of data to send
/// @return Future<int> HTTP status code of the response
/// @return Future[int] HTTP status code of the response
static Future<int> httpRequest({Map<String, String>? saveDataMap, String? saveDataString}) async {
// print(jsonEncode(place));
@@ -30,12 +30,22 @@ class HttpRequestService {
Response response =
Response(requestOptions: RequestOptions(path: ''), statusCode: 400);
try {
// Choose endpoint based on data type (camera trap vs excursion)
if (saveDataMap != null && saveDataMap.containsKey("CID") || saveDataString != null && saveDataString.contains("CID")) {
// write username in Sent field
if (saveDataMap != null) {
saveDataMap["Sent"] = prefs.getString("addresse1") ?? "";
} else if (saveDataString != null){
saveDataString.replaceAll("\"Sent\": \"\"", "\"Sent\": \"${prefs.getString("addresse1")}\"");
}
response = await dio.post(prefs.getString('fotofallenApiAddress') ?? "",
data: saveDataMap == null ? saveDataString : jsonEncode(saveDataMap));
} else {
// write username in Sent field
response = await dio.post(prefs.getString('exkursionenApiAddress') ?? "",
data: saveDataMap == null ? saveDataString : jsonEncode(saveDataMap));
}