This commit is contained in:
@@ -2,10 +2,13 @@
|
||||
#include "master.h"
|
||||
#include <Arduino.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <preferencemanager.h>
|
||||
|
||||
const char *BACKEND_SERVER = "http://db.reptilfpv.de:3000";
|
||||
extern String licence; // Declare licence as an external variable defined elsewhere
|
||||
String BACKEND_TOKEN = licence; // Use the licence as the token for authentication
|
||||
const char *BACKEND_SERVER = "https://ninja.reptilfpv.de";
|
||||
extern String
|
||||
licence; // Declare licence as an external variable defined elsewhere
|
||||
String BACKEND_TOKEN =
|
||||
licence; // Use the licence as the token for authentication
|
||||
|
||||
bool backendOnline() {
|
||||
|
||||
@@ -17,7 +20,7 @@ bool backendOnline() {
|
||||
}
|
||||
|
||||
HTTPClient http;
|
||||
http.begin(String(BACKEND_SERVER) + "/api/health");
|
||||
http.begin(String(BACKEND_SERVER) + "/v1/private/health");
|
||||
http.addHeader("Authorization", String("Bearer ") + BACKEND_TOKEN);
|
||||
|
||||
int httpCode = http.GET();
|
||||
@@ -53,7 +56,7 @@ UserData checkUser(const String &uid) {
|
||||
}
|
||||
|
||||
HTTPClient http;
|
||||
http.begin(String(BACKEND_SERVER) + "/api/users/find");
|
||||
http.begin(String(BACKEND_SERVER) + "/v1/private/users/find");
|
||||
http.addHeader("Content-Type", "application/json");
|
||||
http.addHeader("Authorization", String("Bearer ") + BACKEND_TOKEN);
|
||||
|
||||
@@ -95,17 +98,16 @@ bool enterUserData(const String &uid, const String &firstname,
|
||||
}
|
||||
|
||||
HTTPClient http;
|
||||
http.begin(String(BACKEND_SERVER) + "/api/users/insert");
|
||||
http.begin(String(BACKEND_SERVER) + "/v1/private/create-player");
|
||||
http.addHeader("Content-Type", "application/json");
|
||||
http.addHeader("Authorization", String("Bearer ") + BACKEND_TOKEN);
|
||||
|
||||
// Create JSON payload
|
||||
StaticJsonDocument<256> requestDoc;
|
||||
requestDoc["uid"] = uid;
|
||||
requestDoc["vorname"] = firstname;
|
||||
requestDoc["nachname"] = lastname;
|
||||
requestDoc["geburtsdatum"] = geburtsdatum;
|
||||
requestDoc["alter"] = alter;
|
||||
requestDoc["rfiduid"] = uid;
|
||||
requestDoc["firstname"] = firstname;
|
||||
requestDoc["lastname"] = lastname;
|
||||
requestDoc["birthdate"] = geburtsdatum;
|
||||
|
||||
String requestBody;
|
||||
serializeJson(requestDoc, requestBody);
|
||||
@@ -133,7 +135,7 @@ JsonDocument getAllLocations() {
|
||||
}
|
||||
|
||||
HTTPClient http;
|
||||
http.begin(String(BACKEND_SERVER) + "/api/location/");
|
||||
http.begin(String(BACKEND_SERVER) + "/v1/private/locations");
|
||||
http.addHeader("Authorization", String("Bearer ") + BACKEND_TOKEN);
|
||||
|
||||
int httpCode = http.GET();
|
||||
@@ -185,5 +187,36 @@ void setupBackendRoutes(AsyncWebServer &server) {
|
||||
request->send(200, "application/json", result);
|
||||
});
|
||||
|
||||
server.on("/api/set-local-location", HTTP_POST,
|
||||
[](AsyncWebServerRequest *request) {
|
||||
Serial.println("/api/set-local-location called");
|
||||
String locationId;
|
||||
if (request->hasParam("locationId", true)) {
|
||||
locationId = request->getParam("locationId", true)->value();
|
||||
}
|
||||
if (locationId.length() > 0) {
|
||||
saveLocationIdToPrefs(locationId);
|
||||
DynamicJsonDocument doc(64);
|
||||
doc["success"] = true;
|
||||
String result;
|
||||
serializeJson(doc, result);
|
||||
request->send(200, "application/json", result);
|
||||
} else {
|
||||
request->send(400, "application/json", "{\"success\":false}");
|
||||
}
|
||||
});
|
||||
|
||||
server.on("/api/get-local-location", HTTP_GET,
|
||||
[](AsyncWebServerRequest *request) {
|
||||
String locationId = getLocationIdFromPrefs();
|
||||
DynamicJsonDocument doc(64);
|
||||
doc["locationId"] = locationId;
|
||||
String result;
|
||||
serializeJson(doc, result);
|
||||
request->send(200, "application/json", result);
|
||||
|
||||
// Andere Logik wie in getBestLocs
|
||||
});
|
||||
|
||||
// Add more routes as needed
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user