refactor: Move API-Endpoint-Functions to /api/talas_v5_DB/ folder for better organization
This commit is contained in:
@@ -128,7 +128,9 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const fetchPoiData = async (idPoi) => {
|
const fetchPoiData = async (idPoi) => {
|
||||||
const response = await fetch(`/api/getPoiById?idPoi=${idPoi}`);
|
const response = await fetch(
|
||||||
|
`/api/talas_v5_DB/pois/getPoiById?idPoi=${idPoi}`
|
||||||
|
);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
console.error("Fehler beim Abrufen der POI-Daten");
|
console.error("Fehler beim Abrufen der POI-Daten");
|
||||||
return;
|
return;
|
||||||
@@ -227,7 +229,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
};
|
};
|
||||||
// Funktion zum Aktualisieren der Position in der Datenbank
|
// Funktion zum Aktualisieren der Position in der Datenbank
|
||||||
const updateLocationInDatabase = async (id, newLatitude, newLongitude) => {
|
const updateLocationInDatabase = async (id, newLatitude, newLongitude) => {
|
||||||
const response = await fetch("/api/updateLocation", {
|
const response = await fetch("/api/talas_v5_DB/pois/updateLocation", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@@ -1044,7 +1046,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchPoiTypData = async () => {
|
const fetchPoiTypData = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/readPoiTyp");
|
const response = await fetch("/api/talas_v5_DB/poiTyp/readPoiTyp");
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
setPoiTypData(data); // Daten im Recoil State speichern
|
setPoiTypData(data); // Daten im Recoil State speichern
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -1069,7 +1071,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchPoiTypData = async () => {
|
const fetchPoiTypData = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/readPoiTyp");
|
const response = await fetch("/api/talas_v5_DB/poiTyp/readPoiTyp");
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
const map = new Map();
|
const map = new Map();
|
||||||
data.forEach((item) => map.set(item.idPoiTyp, item.name));
|
data.forEach((item) => map.set(item.idPoiTyp, item.name));
|
||||||
@@ -1135,7 +1137,9 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
|
|
||||||
const fetchDeviceNameById = async (idLD) => {
|
const fetchDeviceNameById = async (idLD) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/locationDeviceNameById?idLD=${idLD}`);
|
const response = await fetch(
|
||||||
|
`/api/talas_v5_DB/locationDevice/locationDeviceNameById?idLD=${idLD}`
|
||||||
|
);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return data.name;
|
return data.name;
|
||||||
@@ -1197,7 +1201,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchPoiData = async () => {
|
const fetchPoiData = async () => {
|
||||||
const response = await fetch("/api/poi-icons");
|
const response = await fetch("/api/talas_v5_DB/pois/poi-icons");
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
setPoiData(data);
|
setPoiData(data);
|
||||||
//console.log("poiData icons:", data);
|
//console.log("poiData icons:", data);
|
||||||
|
|||||||
@@ -128,7 +128,9 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const fetchPoiData = async (idPoi) => {
|
const fetchPoiData = async (idPoi) => {
|
||||||
const response = await fetch(`/api/getPoiById?idPoi=${idPoi}`);
|
const response = await fetch(
|
||||||
|
`/api/talas_v5_DB/pois/getPoiById?idPoi=${idPoi}`
|
||||||
|
);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
console.error("Fehler beim Abrufen der POI-Daten");
|
console.error("Fehler beim Abrufen der POI-Daten");
|
||||||
return;
|
return;
|
||||||
@@ -227,7 +229,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
};
|
};
|
||||||
// Funktion zum Aktualisieren der Position in der Datenbank
|
// Funktion zum Aktualisieren der Position in der Datenbank
|
||||||
const updateLocationInDatabase = async (id, newLatitude, newLongitude) => {
|
const updateLocationInDatabase = async (id, newLatitude, newLongitude) => {
|
||||||
const response = await fetch("/api/updateLocation", {
|
const response = await fetch("/api/talas_v5_DB/pois/updateLocation", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@@ -1044,7 +1046,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchPoiTypData = async () => {
|
const fetchPoiTypData = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/readPoiTyp");
|
const response = await fetch("/api/talas_v5_DB/poiTyp/readPoiTyp");
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
setPoiTypData(data); // Daten im Recoil State speichern
|
setPoiTypData(data); // Daten im Recoil State speichern
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -1069,7 +1071,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchPoiTypData = async () => {
|
const fetchPoiTypData = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/readPoiTyp");
|
const response = await fetch("/api/talas_v5_DB/poiTyp/readPoiTyp");
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
const map = new Map();
|
const map = new Map();
|
||||||
data.forEach((item) => map.set(item.idPoiTyp, item.name));
|
data.forEach((item) => map.set(item.idPoiTyp, item.name));
|
||||||
@@ -1135,7 +1137,9 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
|
|
||||||
const fetchDeviceNameById = async (idLD) => {
|
const fetchDeviceNameById = async (idLD) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/locationDeviceNameById?idLD=${idLD}`);
|
const response = await fetch(
|
||||||
|
`/api/talas_v5_DB/locationDevice/locationDeviceNameById?idLD=${idLD}`
|
||||||
|
);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return data.name;
|
return data.name;
|
||||||
@@ -1197,7 +1201,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchPoiData = async () => {
|
const fetchPoiData = async () => {
|
||||||
const response = await fetch("/api/poi-icons");
|
const response = await fetch("/api/talas_v5_DB/pois/poi-icons");
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
setPoiData(data);
|
setPoiData(data);
|
||||||
//console.log("poiData icons:", data);
|
//console.log("poiData icons:", data);
|
||||||
|
|||||||
@@ -3,11 +3,9 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { useRecoilValue } from "recoil";
|
import { useRecoilValue } from "recoil";
|
||||||
import { selectedPoiState } from "../store/atoms/poiState";
|
import { selectedPoiState } from "../store/atoms/poiState";
|
||||||
import { currentPoiState } from '../store/atoms/currentPoiState';
|
import { currentPoiState } from "../store/atoms/currentPoiState";
|
||||||
|
|
||||||
|
|
||||||
const PoiUpdateModal = ({ onClose, poiData }) => {
|
const PoiUpdateModal = ({ onClose, poiData }) => {
|
||||||
|
|
||||||
const currentPoi = useRecoilValue(currentPoiState);
|
const currentPoi = useRecoilValue(currentPoiState);
|
||||||
const selectedPoi = useRecoilValue(selectedPoiState);
|
const selectedPoi = useRecoilValue(selectedPoiState);
|
||||||
const [poiId, setPoiId] = useState(poiData ? poiData.idPoi : "");
|
const [poiId, setPoiId] = useState(poiData ? poiData.idPoi : "");
|
||||||
@@ -18,8 +16,6 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
|
|||||||
const [deviceName, setDeviceName] = useState("");
|
const [deviceName, setDeviceName] = useState("");
|
||||||
const [idLD, setIdLD] = useState(poiData ? poiData.idLD : "");
|
const [idLD, setIdLD] = useState(poiData ? poiData.idLD : "");
|
||||||
const [idLocationDevice, setIdLocationDevice] = useState("");
|
const [idLocationDevice, setIdLocationDevice] = useState("");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const [description, setDescription] = useState(
|
const [description, setDescription] = useState(
|
||||||
poiData ? poiData.description : ""
|
poiData ? poiData.description : ""
|
||||||
@@ -44,7 +40,7 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
|
|||||||
}
|
}
|
||||||
}, [poiData]);
|
}, [poiData]);
|
||||||
|
|
||||||
/* const fetchDeviceNameById = async (idLD) => {
|
/* const fetchDeviceNameById = async (idLD) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/getDeviceNameById?idLD=${idLD}`);
|
const response = await fetch(`/api/getDeviceNameById?idLD=${idLD}`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
@@ -54,9 +50,9 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
|
|||||||
}
|
}
|
||||||
}; */
|
}; */
|
||||||
|
|
||||||
/* const fetchDeviceNameById = async (idLD) => {
|
/* const fetchDeviceNameById = async (idLD) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/locationDeviceNameById?idLD=${idLD}`);
|
const response = await fetch(`/api/talas_v5_DB/locationDevice/locationDeviceNameById?idLD=${idLD}`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
setDeviceName(data.deviceName);
|
setDeviceName(data.deviceName);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -70,7 +66,7 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
|
|||||||
if (poiData && poiData.idLD) {
|
if (poiData && poiData.idLD) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`/api/getDeviceIdById?idLD=${poiData.idLD}`
|
`/api/talas_v5_DB/locationDevice/getDeviceIdById?idLD=${poiData.idLD}`
|
||||||
);
|
);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (data) setDeviceName(data.name);
|
if (data) setDeviceName(data.name);
|
||||||
@@ -87,9 +83,12 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
|
|||||||
const handleDeletePoi = async () => {
|
const handleDeletePoi = async () => {
|
||||||
if (confirm("Sind Sie sicher, dass Sie diesen POI löschen möchten?")) {
|
if (confirm("Sind Sie sicher, dass Sie diesen POI löschen möchten?")) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/deletePoi?id=${poiId}`, {
|
const response = await fetch(
|
||||||
method: "DELETE",
|
`/api/talas_v5_DB/pois/deletePoi?id=${poiId}`,
|
||||||
});
|
{
|
||||||
|
method: "DELETE",
|
||||||
|
}
|
||||||
|
);
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
alert("POI wurde erfolgreich gelöscht.");
|
alert("POI wurde erfolgreich gelöscht.");
|
||||||
onClose(); // Close the modal
|
onClose(); // Close the modal
|
||||||
@@ -109,11 +108,11 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchPoiTypData = async () => {
|
const fetchPoiTypData = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/readPoiTyp");
|
const response = await fetch("/api/talas_v5_DB/poiTyp/readPoiTyp");
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
setPoiTypData(data);
|
setPoiTypData(data);
|
||||||
if (selectedPoi && data) {
|
if (selectedPoi && data) {
|
||||||
const matchingType = data.find(pt => pt.name === selectedPoi.typ);
|
const matchingType = data.find((pt) => pt.name === selectedPoi.typ);
|
||||||
if (matchingType) {
|
if (matchingType) {
|
||||||
setPoiTypeId(matchingType.idPoiTyp);
|
setPoiTypeId(matchingType.idPoiTyp);
|
||||||
}
|
}
|
||||||
@@ -151,43 +150,44 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
|
|||||||
};
|
};
|
||||||
fetchData();
|
fetchData();
|
||||||
}, []);
|
}, []);
|
||||||
//--------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------
|
||||||
// Fetch device name basierend auf der Geräte-ID
|
// Fetch device name basierend auf der Geräte-ID
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("currentPoi von PoiUpdateModal.js : ", currentPoi.idLD);
|
console.log("currentPoi von PoiUpdateModal.js : ", currentPoi.idLD);
|
||||||
fetch('/api/locationDevices')
|
fetch("/api/talas_v5_DB/locationDevice/locationDevices")
|
||||||
.then(response => response.json())
|
.then((response) => response.json())
|
||||||
.then(data => {
|
.then((data) => {
|
||||||
setLocationDeviceData(data);
|
setLocationDeviceData(data);
|
||||||
console.log("Standort- und Gerätedaten 3:", data);
|
console.log("Standort- und Gerätedaten 3:", data);
|
||||||
console.log("Standort- und Gerätedaten 3 poiData:", poiData);
|
console.log("Standort- und Gerätedaten 3 poiData:", poiData);
|
||||||
// Findet das Gerät, das der aktuellen IDLD entspricht
|
// Findet das Gerät, das der aktuellen IDLD entspricht
|
||||||
const currentDevice = data.find(device => device.idLD === currentPoi.idLD);
|
const currentDevice = data.find(
|
||||||
if (currentDevice) {
|
(device) => device.idLD === currentPoi.idLD
|
||||||
setDeviceName(currentDevice.name);
|
);
|
||||||
}
|
if (currentDevice) {
|
||||||
})
|
setDeviceName(currentDevice.name);
|
||||||
.catch(error => {
|
}
|
||||||
console.error('Fehler beim Abrufen der Gerätedaten:', error);
|
})
|
||||||
setLocationDeviceData([]);
|
.catch((error) => {
|
||||||
});
|
console.error("Fehler beim Abrufen der Gerätedaten:", error);
|
||||||
}, [poiData?.idLD,currentPoi]);
|
setLocationDeviceData([]);
|
||||||
|
});
|
||||||
|
}, [poiData?.idLD, currentPoi]);
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------
|
||||||
//--------------------------------------------------------------------------------------------
|
|
||||||
// Angenommen, deviceName enthält die Geräte-ID
|
// Angenommen, deviceName enthält die Geräte-ID
|
||||||
//const idLD = deviceName; // Stellen Sie sicher, dass dies eine ID ist und kein Name
|
//const idLD = deviceName; // Stellen Sie sicher, dass dies eine ID ist und kein Name
|
||||||
|
|
||||||
const handleSubmit = async (event) => {
|
const handleSubmit = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const idLDResponse = await fetch(
|
const idLDResponse = await fetch(
|
||||||
`/api/getDeviceId?deviceName=${encodeURIComponent(deviceName)}`
|
`/api/talas_v5_DB/locationDevice/getDeviceId?deviceName=${encodeURIComponent(deviceName)}`
|
||||||
);
|
);
|
||||||
const idLDData = await idLDResponse.json();
|
const idLDData = await idLDResponse.json();
|
||||||
const idLD = idLDData.idLD;
|
const idLD = idLDData.idLD;
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/updatePoi", {
|
const response = await fetch("/api/talas_v5_DB/pois/updatePoi", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -220,9 +220,15 @@ useEffect(() => {
|
|||||||
//ausgewählte poi Informationen in Console anzeigen
|
//ausgewählte poi Informationen in Console anzeigen
|
||||||
console.log("Selected POI:", selectedPoi);
|
console.log("Selected POI:", selectedPoi);
|
||||||
console.log("Selected POI Gerät id in poiUpdateModal.js:", selectedPoi.id);
|
console.log("Selected POI Gerät id in poiUpdateModal.js:", selectedPoi.id);
|
||||||
console.log("Selected POI Typ name in poiUpdateModal.js:", selectedPoi.typ);//als Typ in dropdown menu
|
console.log("Selected POI Typ name in poiUpdateModal.js:", selectedPoi.typ); //als Typ in dropdown menu
|
||||||
console.log("Selected POI Beschreibung in poiUpdateModal.js:", selectedPoi.description);
|
console.log(
|
||||||
console.log("Selected POI Gerät deviceId in poiUpdateModal.js:", selectedPoi.deviceId);
|
"Selected POI Beschreibung in poiUpdateModal.js:",
|
||||||
|
selectedPoi.description
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
"Selected POI Gerät deviceId in poiUpdateModal.js:",
|
||||||
|
selectedPoi.deviceId
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={handleSubmit} className="m-0 p-2 w-full">
|
<form onSubmit={handleSubmit} className="m-0 p-2 w-full">
|
||||||
@@ -252,12 +258,16 @@ useEffect(() => {
|
|||||||
onChange={(e) => setDeviceName(e.target.value)}
|
onChange={(e) => setDeviceName(e.target.value)}
|
||||||
className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm"
|
className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm"
|
||||||
>
|
>
|
||||||
{locationDeviceData.map((device, index) => (
|
{locationDeviceData.map(
|
||||||
console.log("device.id und name:", device),
|
(device, index) => (
|
||||||
<option key={index} value={device.id}>
|
console.log("device.id und name:", device),
|
||||||
{device.name}
|
(
|
||||||
</option>
|
<option key={index} value={device.id}>
|
||||||
))}
|
{device.name}
|
||||||
|
</option>
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export const updateLocationInDatabase = async (
|
|||||||
newLatitude,
|
newLatitude,
|
||||||
newLongitude
|
newLongitude
|
||||||
) => {
|
) => {
|
||||||
const response = await fetch("/api/updateLocation", {
|
const response = await fetch("/api/talas_v5_DB/pois/updateLocation", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { useRecoilValue, useRecoilState, useSetRecoilState } from "recoil";
|
|||||||
import { readPoiMarkersStore } from "../store/selectors/readPoiMarkersStore";
|
import { readPoiMarkersStore } from "../store/selectors/readPoiMarkersStore";
|
||||||
import { poiReadFromDbTriggerAtom } from "../store/atoms/poiReadFromDbTriggerAtom";
|
import { poiReadFromDbTriggerAtom } from "../store/atoms/poiReadFromDbTriggerAtom";
|
||||||
|
|
||||||
|
|
||||||
const ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
const ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
||||||
const [poiTypData, setpoiTypData] = useState(); // Recoil State verwenden
|
const [poiTypData, setpoiTypData] = useState(); // Recoil State verwenden
|
||||||
const [name, setName] = useState("");
|
const [name, setName] = useState("");
|
||||||
@@ -21,7 +20,7 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchpoiTypData = async () => {
|
const fetchpoiTypData = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/readPoiTyp");
|
const response = await fetch("/api/talas_v5_DB/poiTyp/readPoiTyp");
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
setpoiTypData(data);
|
setpoiTypData(data);
|
||||||
if (data && data.length > 0) {
|
if (data && data.length > 0) {
|
||||||
@@ -96,7 +95,7 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
|||||||
.idLD,
|
.idLD,
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await fetch("/api/addLocation", {
|
const response = await fetch("/api/talas_v5_DB/pois/addLocation", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify(formData),
|
body: JSON.stringify(formData),
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import mysql from 'mysql';
|
// /pages/api/talas_v5_DB/gisLines/readGisLines.js
|
||||||
|
import mysql from "mysql";
|
||||||
|
|
||||||
const dbConfig = {
|
const dbConfig = {
|
||||||
host: process.env.DB_HOST,
|
host: process.env.DB_HOST,
|
||||||
@@ -11,26 +12,28 @@ const dbConfig = {
|
|||||||
const connection = mysql.createConnection(dbConfig);
|
const connection = mysql.createConnection(dbConfig);
|
||||||
connection.connect((err) => {
|
connection.connect((err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Fehler beim Verbinden:', err.stack);
|
console.error("Fehler beim Verbinden:", err.stack);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log('Database connected successfully.');
|
console.log("Database connected successfully.");
|
||||||
});
|
});
|
||||||
|
|
||||||
export default function handler(req, res) {
|
export default function handler(req, res) {
|
||||||
if (req.method !== 'GET') {
|
if (req.method !== "GET") {
|
||||||
return res.status(405).json({ error: 'Nur GET Methode erlaubt' });
|
return res.status(405).json({ error: "Nur GET Methode erlaubt" });
|
||||||
}
|
}
|
||||||
const query = 'SELECT * FROM talas_v5.gis_lines;';
|
const query = "SELECT * FROM talas_v5.gis_lines;";
|
||||||
connection.query(query, (error, results) => {
|
connection.query(query, (error, results) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('Fehler beim Abrufen der gis_lines:', error);
|
console.error("Fehler beim Abrufen der gis_lines:", error);
|
||||||
return res.status(500).json({ error: 'Fehler beim Abrufen der gis_lines' });
|
return res
|
||||||
|
.status(500)
|
||||||
|
.json({ error: "Fehler beim Abrufen der gis_lines" });
|
||||||
}
|
}
|
||||||
if (results.length > 0) {
|
if (results.length > 0) {
|
||||||
res.json(results);
|
res.json(results);
|
||||||
} else {
|
} else {
|
||||||
res.status(404).json({ error: 'Gerät nicht gefunden' });
|
res.status(404).json({ error: "Gerät nicht gefunden" });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// API in /api/getDeviceId.js
|
// API in /api/talas_v5_DB/locationDevice/getDeviceId.js
|
||||||
import mysql from "mysql";
|
import mysql from "mysql";
|
||||||
|
|
||||||
const dbConfig = {
|
const dbConfig = {
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
// API in /api/locationDeviceNameById.js
|
// API in /api/talas_v5_DB/locationDevice/locationDeviceNameById.js
|
||||||
import mysql from "mysql";
|
import mysql from "mysql";
|
||||||
|
|
||||||
|
|
||||||
const dbConfig = {
|
const dbConfig = {
|
||||||
host: process.env.DB_HOST,
|
host: process.env.DB_HOST,
|
||||||
user: process.env.DB_USER,
|
user: process.env.DB_USER,
|
||||||
@@ -28,7 +27,9 @@ export default function handler(req, res) {
|
|||||||
connection.query(query, [idLD], (error, results) => {
|
connection.query(query, [idLD], (error, results) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error("Fehler beim Abrufen des Gerätenamens:", error);
|
console.error("Fehler beim Abrufen des Gerätenamens:", error);
|
||||||
return res.status(500).json({ error: "Fehler beim Abrufen des Gerätenamens" });
|
return res
|
||||||
|
.status(500)
|
||||||
|
.json({ error: "Fehler beim Abrufen des Gerätenamens" });
|
||||||
}
|
}
|
||||||
if (results.length > 0) {
|
if (results.length > 0) {
|
||||||
res.json({ name: results[0].name });
|
res.json({ name: results[0].name });
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
// API in /api/locationDevices.js
|
// API in /api/talas_v5_DB/locationDevice/locationDevices.js
|
||||||
import mysql from 'mysql';
|
import mysql from "mysql";
|
||||||
|
|
||||||
const dbConfig = {
|
const dbConfig = {
|
||||||
host: process.env.DB_HOST,
|
host: process.env.DB_HOST,
|
||||||
@@ -26,7 +26,9 @@ export default function handler(req, res) {
|
|||||||
connection.query(query, (error, results) => {
|
connection.query(query, (error, results) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error("Fehler beim Abrufen der Geräteinformationen:", error);
|
console.error("Fehler beim Abrufen der Geräteinformationen:", error);
|
||||||
return res.status(500).json({ error: "Fehler beim Abrufen der Geräteinformationen" });
|
return res
|
||||||
|
.status(500)
|
||||||
|
.json({ error: "Fehler beim Abrufen der Geräteinformationen" });
|
||||||
}
|
}
|
||||||
res.json(results);
|
res.json(results);
|
||||||
});
|
});
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// pages/api/readPoiTyp.js
|
// pages/api/talas_v5_DB/poiTyp/readPoiTyp.js
|
||||||
import mysql from "mysql";
|
import mysql from "mysql";
|
||||||
|
|
||||||
const pool = mysql.createPool({
|
const pool = mysql.createPool({
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// pages/api/addLocation.js
|
// pages/api/talas_v5_DB/pois/addLocation.js
|
||||||
import mysql from "mysql";
|
import mysql from "mysql";
|
||||||
|
|
||||||
const dbConfig = {
|
const dbConfig = {
|
||||||
@@ -26,12 +26,10 @@ export default function handler(req, res) {
|
|||||||
console.error("Fehler beim Einfügen des Standorts:", error);
|
console.error("Fehler beim Einfügen des Standorts:", error);
|
||||||
return res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
|
return res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
|
||||||
}
|
}
|
||||||
res
|
res.status(200).json({
|
||||||
.status(200)
|
id: results.insertId,
|
||||||
.json({
|
message: "Standort erfolgreich hinzugefügt",
|
||||||
id: results.insertId,
|
});
|
||||||
message: "Standort erfolgreich hinzugefügt",
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res.setHeader("Allow", ["POST"]);
|
res.setHeader("Allow", ["POST"]);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// pages/api/deletePoi.js
|
// pages/api/talas_v5_DB/pois/deletePoi.js
|
||||||
import mysql from "mysql";
|
import mysql from "mysql";
|
||||||
|
|
||||||
// Datenbankkonfiguration
|
// Datenbankkonfiguration
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// pages/api/getPoiById.js
|
// pages/api/talas_v5_DB/pois/getPoiById.js
|
||||||
import mysql from "mysql";
|
import mysql from "mysql";
|
||||||
|
|
||||||
const dbConfig = {
|
const dbConfig = {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// pages/api/poi-icons.js
|
// pages/api/talas_v5_DB/pois/poi-icons.js
|
||||||
import mysql from "mysql";
|
import mysql from "mysql";
|
||||||
|
|
||||||
const dbConfig = {
|
const dbConfig = {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// pages/api/readLocations.js
|
// pages/api/talas_v5_DB/pois/readLocations.js
|
||||||
import mysql from "mysql";
|
import mysql from "mysql";
|
||||||
|
|
||||||
const dbConfig = {
|
const dbConfig = {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// pages/api/updateLocation.js
|
// pages/api/talas_v5_DB/pois/updateLocation.js
|
||||||
import mysql from "mysql";
|
import mysql from "mysql";
|
||||||
import util from "util";
|
import util from "util";
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// pages/api/updatePoi.js
|
// pages/api/talas_v5_DB/pois/updatePoi.js
|
||||||
import mysql from "mysql";
|
import mysql from "mysql";
|
||||||
|
|
||||||
const dbConfig = {
|
const dbConfig = {
|
||||||
@@ -18,7 +18,7 @@ export default function Home() {
|
|||||||
|
|
||||||
const loadData = async () => {
|
const loadData = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/readLocations");
|
const response = await fetch("/api/talas_v5_DB/pois/readLocations");
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Fehler beim Laden der Standortdaten");
|
throw new Error("Fehler beim Laden der Standortdaten");
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ export default function Home() {
|
|||||||
|
|
||||||
const handleAddLocation = async (name, type, lat, lng) => {
|
const handleAddLocation = async (name, type, lat, lng) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/addLocation", {
|
const response = await fetch("/api/talas_v5_DB/pois/addLocation", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ name, type, latitude: lat, longitude: lng }),
|
body: JSON.stringify({ name, type, latitude: lat, longitude: lng }),
|
||||||
|
|||||||
Reference in New Issue
Block a user