Location Speichern geht? abrufen der gespeicherten location aus properties muss noch gemacht werden

This commit is contained in:
Carsten Graf
2025-06-11 22:52:30 +02:00
parent 22cc4fe99c
commit b6fa2d69e7
8 changed files with 319 additions and 14 deletions

View File

@@ -82,7 +82,7 @@ UserData checkUser(const String& uid) {
}
//Function to enter user data into the database
bool enterUserData(const String& uid, const String& firstname, const String& lastname, int alter) {
bool enterUserData(const String& uid, const String& firstname, const String& lastname, const String& geburtsdatum, int alter) {
if (!backendOnline()) {
Serial.println("No internet connection, cannot enter user data.");
return false;
@@ -98,6 +98,7 @@ bool enterUserData(const String& uid, const String& firstname, const String& las
requestDoc["uid"] = uid;
requestDoc["vorname"] = firstname;
requestDoc["nachname"] = lastname;
requestDoc["geburtsdatum"] = geburtsdatum;
requestDoc["alter"] = alter;
String requestBody;
@@ -116,13 +117,43 @@ bool enterUserData(const String& uid, const String& firstname, const String& las
}
}
JsonDocument getAllLocations() {
JsonDocument locations; // Allocate memory for the JSON document
if (!backendOnline()) {
Serial.println("No internet connection, cannot fetch locations.");
return locations; // Return an empty document
}
HTTPClient http;
http.begin(String(BACKEND_SERVER) + "/api/location/");
http.addHeader("Authorization", String("Bearer ") + BACKEND_TOKEN);
int httpCode = http.GET();
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
DeserializationError error = deserializeJson(locations, payload);
if (error) {
Serial.println("Failed to parse locations JSON.");
}
} else {
Serial.printf("Failed to fetch locations, HTTP code: %d\n", httpCode);
}
http.end();
return locations; // Return the populated JSON document
}
// Keep this for backward compatibility
bool userExists(const String& uid) {
return checkUser(uid).exists;
}
//Routes from the Frontend into here and then into DB backend.
void setupBackendRoutes(AsyncWebServer& server) {
server.on("/api/health", HTTP_GET, [](AsyncWebServerRequest *request) {
@@ -142,6 +173,15 @@ void setupBackendRoutes(AsyncWebServer& server) {
// Handle user retrieval logic here
});
//Location routes /api/location/
server.on("/api/location/", HTTP_GET, [](AsyncWebServerRequest *request){
String result;
serializeJson(getAllLocations(), result);
request->send(200, "application/json", result);
});
// Add more routes as needed
}