diff --git a/components/MapComponent - Kopie.js b/components/MapComponent - Kopie.js index b598ef2a5..865ebe8d2 100644 --- a/components/MapComponent - Kopie.js +++ b/components/MapComponent - Kopie.js @@ -128,7 +128,9 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { }; 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) { console.error("Fehler beim Abrufen der POI-Daten"); return; @@ -227,7 +229,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { }; // Funktion zum Aktualisieren der Position in der Datenbank const updateLocationInDatabase = async (id, newLatitude, newLongitude) => { - const response = await fetch("/api/updateLocation", { + const response = await fetch("/api/talas_v5_DB/pois/updateLocation", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ @@ -1044,7 +1046,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { useEffect(() => { const fetchPoiTypData = async () => { try { - const response = await fetch("/api/readPoiTyp"); + const response = await fetch("/api/talas_v5_DB/poiTyp/readPoiTyp"); const data = await response.json(); setPoiTypData(data); // Daten im Recoil State speichern } catch (error) { @@ -1069,7 +1071,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { useEffect(() => { const fetchPoiTypData = async () => { try { - const response = await fetch("/api/readPoiTyp"); + const response = await fetch("/api/talas_v5_DB/poiTyp/readPoiTyp"); const data = await response.json(); const map = new Map(); data.forEach((item) => map.set(item.idPoiTyp, item.name)); @@ -1135,7 +1137,9 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { const fetchDeviceNameById = async (idLD) => { 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(); if (response.ok) { return data.name; @@ -1197,7 +1201,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { useEffect(() => { 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(); setPoiData(data); //console.log("poiData icons:", data); diff --git a/components/MapComponent.js b/components/MapComponent.js index ead011182..95eb26724 100644 --- a/components/MapComponent.js +++ b/components/MapComponent.js @@ -128,7 +128,9 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { }; 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) { console.error("Fehler beim Abrufen der POI-Daten"); return; @@ -227,7 +229,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { }; // Funktion zum Aktualisieren der Position in der Datenbank const updateLocationInDatabase = async (id, newLatitude, newLongitude) => { - const response = await fetch("/api/updateLocation", { + const response = await fetch("/api/talas_v5_DB/pois/updateLocation", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ @@ -1044,7 +1046,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { useEffect(() => { const fetchPoiTypData = async () => { try { - const response = await fetch("/api/readPoiTyp"); + const response = await fetch("/api/talas_v5_DB/poiTyp/readPoiTyp"); const data = await response.json(); setPoiTypData(data); // Daten im Recoil State speichern } catch (error) { @@ -1069,7 +1071,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { useEffect(() => { const fetchPoiTypData = async () => { try { - const response = await fetch("/api/readPoiTyp"); + const response = await fetch("/api/talas_v5_DB/poiTyp/readPoiTyp"); const data = await response.json(); const map = new Map(); data.forEach((item) => map.set(item.idPoiTyp, item.name)); @@ -1135,7 +1137,9 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { const fetchDeviceNameById = async (idLD) => { 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(); if (response.ok) { return data.name; @@ -1197,7 +1201,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { useEffect(() => { 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(); setPoiData(data); //console.log("poiData icons:", data); diff --git a/components/PoiUpdateModal.js b/components/PoiUpdateModal.js index 71c0b0193..c424cc625 100644 --- a/components/PoiUpdateModal.js +++ b/components/PoiUpdateModal.js @@ -3,11 +3,9 @@ import React, { useState, useEffect } from "react"; import { useRecoilValue } from "recoil"; import { selectedPoiState } from "../store/atoms/poiState"; -import { currentPoiState } from '../store/atoms/currentPoiState'; - +import { currentPoiState } from "../store/atoms/currentPoiState"; const PoiUpdateModal = ({ onClose, poiData }) => { - const currentPoi = useRecoilValue(currentPoiState); const selectedPoi = useRecoilValue(selectedPoiState); const [poiId, setPoiId] = useState(poiData ? poiData.idPoi : ""); @@ -18,8 +16,6 @@ const PoiUpdateModal = ({ onClose, poiData }) => { const [deviceName, setDeviceName] = useState(""); const [idLD, setIdLD] = useState(poiData ? poiData.idLD : ""); const [idLocationDevice, setIdLocationDevice] = useState(""); - - const [description, setDescription] = useState( poiData ? poiData.description : "" @@ -44,7 +40,7 @@ const PoiUpdateModal = ({ onClose, poiData }) => { } }, [poiData]); -/* const fetchDeviceNameById = async (idLD) => { + /* const fetchDeviceNameById = async (idLD) => { try { const response = await fetch(`/api/getDeviceNameById?idLD=${idLD}`); const data = await response.json(); @@ -54,9 +50,9 @@ const PoiUpdateModal = ({ onClose, poiData }) => { } }; */ -/* const fetchDeviceNameById = async (idLD) => { + /* const fetchDeviceNameById = async (idLD) => { 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(); setDeviceName(data.deviceName); } catch (error) { @@ -70,7 +66,7 @@ const PoiUpdateModal = ({ onClose, poiData }) => { if (poiData && poiData.idLD) { try { const response = await fetch( - `/api/getDeviceIdById?idLD=${poiData.idLD}` + `/api/talas_v5_DB/locationDevice/getDeviceIdById?idLD=${poiData.idLD}` ); const data = await response.json(); if (data) setDeviceName(data.name); @@ -87,9 +83,12 @@ const PoiUpdateModal = ({ onClose, poiData }) => { const handleDeletePoi = async () => { if (confirm("Sind Sie sicher, dass Sie diesen POI löschen möchten?")) { try { - const response = await fetch(`/api/deletePoi?id=${poiId}`, { - method: "DELETE", - }); + const response = await fetch( + `/api/talas_v5_DB/pois/deletePoi?id=${poiId}`, + { + method: "DELETE", + } + ); if (response.ok) { alert("POI wurde erfolgreich gelöscht."); onClose(); // Close the modal @@ -109,11 +108,11 @@ const PoiUpdateModal = ({ onClose, poiData }) => { useEffect(() => { const fetchPoiTypData = async () => { try { - const response = await fetch("/api/readPoiTyp"); + const response = await fetch("/api/talas_v5_DB/poiTyp/readPoiTyp"); const data = await response.json(); setPoiTypData(data); if (selectedPoi && data) { - const matchingType = data.find(pt => pt.name === selectedPoi.typ); + const matchingType = data.find((pt) => pt.name === selectedPoi.typ); if (matchingType) { setPoiTypeId(matchingType.idPoiTyp); } @@ -151,43 +150,44 @@ const PoiUpdateModal = ({ onClose, poiData }) => { }; fetchData(); }, []); -//-------------------------------------------------------------------------------------------- -// Fetch device name basierend auf der Geräte-ID + //-------------------------------------------------------------------------------------------- + // Fetch device name basierend auf der Geräte-ID -useEffect(() => { - console.log("currentPoi von PoiUpdateModal.js : ", currentPoi.idLD); - fetch('/api/locationDevices') - .then(response => response.json()) - .then(data => { - setLocationDeviceData(data); - console.log("Standort- und Gerätedaten 3:", data); - console.log("Standort- und Gerätedaten 3 poiData:", poiData); - // Findet das Gerät, das der aktuellen IDLD entspricht - const currentDevice = data.find(device => device.idLD === currentPoi.idLD); - if (currentDevice) { - setDeviceName(currentDevice.name); - } - }) - .catch(error => { - console.error('Fehler beim Abrufen der Gerätedaten:', error); - setLocationDeviceData([]); - }); -}, [poiData?.idLD,currentPoi]); + useEffect(() => { + console.log("currentPoi von PoiUpdateModal.js : ", currentPoi.idLD); + fetch("/api/talas_v5_DB/locationDevice/locationDevices") + .then((response) => response.json()) + .then((data) => { + setLocationDeviceData(data); + console.log("Standort- und Gerätedaten 3:", data); + console.log("Standort- und Gerätedaten 3 poiData:", poiData); + // Findet das Gerät, das der aktuellen IDLD entspricht + const currentDevice = data.find( + (device) => device.idLD === currentPoi.idLD + ); + if (currentDevice) { + setDeviceName(currentDevice.name); + } + }) + .catch((error) => { + console.error("Fehler beim Abrufen der Gerätedaten:", error); + setLocationDeviceData([]); + }); + }, [poiData?.idLD, currentPoi]); - -//-------------------------------------------------------------------------------------------- + //-------------------------------------------------------------------------------------------- // Angenommen, deviceName enthält die Geräte-ID //const idLD = deviceName; // Stellen Sie sicher, dass dies eine ID ist und kein Name const handleSubmit = async (event) => { event.preventDefault(); const idLDResponse = await fetch( - `/api/getDeviceId?deviceName=${encodeURIComponent(deviceName)}` + `/api/talas_v5_DB/locationDevice/getDeviceId?deviceName=${encodeURIComponent(deviceName)}` ); const idLDData = await idLDResponse.json(); const idLD = idLDData.idLD; try { - const response = await fetch("/api/updatePoi", { + const response = await fetch("/api/talas_v5_DB/pois/updatePoi", { method: "POST", headers: { "Content-Type": "application/json", @@ -220,9 +220,15 @@ useEffect(() => { //ausgewählte poi Informationen in Console anzeigen console.log("Selected POI:", selectedPoi); 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 Beschreibung in poiUpdateModal.js:", selectedPoi.description); - console.log("Selected POI Gerät deviceId in poiUpdateModal.js:", selectedPoi.deviceId); + 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( + "Selected POI Gerät deviceId in poiUpdateModal.js:", + selectedPoi.deviceId + ); return (