From 79c0b4e8cfae527de92681842c854eef16d269fb Mon Sep 17 00:00:00 2001 From: ISA Date: Fri, 3 May 2024 09:26:09 +0200 Subject: [PATCH] Rename api/locations to api/readLocations and api/poiTyp to api/readPoiTyp --- components/MapComponent.js | 2 +- components/ShowAddStationPopup.js | 2 +- pages/api/{locations.js => readLocations.js} | 17 +++++++++-------- pages/api/{poiTyp.js => readPoiTyp.js} | 2 +- pages/index.js | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) rename pages/api/{locations.js => readLocations.js} (72%) rename pages/api/{poiTyp.js => readPoiTyp.js} (97%) diff --git a/components/MapComponent.js b/components/MapComponent.js index ea5ffad56..8606cd6b8 100644 --- a/components/MapComponent.js +++ b/components/MapComponent.js @@ -332,7 +332,7 @@ const MapComponent = ({ locations, onLocationUpdate }) => { useEffect(() => { const fetchPoiTypData = async () => { try { - const response = await fetch("/api/poiTyp"); + const response = await fetch("/api/readPoiTyp"); const data = await response.json(); setPoiTypData(data); // Daten im Recoil State speichern } catch (error) { diff --git a/components/ShowAddStationPopup.js b/components/ShowAddStationPopup.js index 06c5a674b..3f269adf9 100644 --- a/components/ShowAddStationPopup.js +++ b/components/ShowAddStationPopup.js @@ -11,7 +11,7 @@ const ShowAddStationPopup = ({ map, latlng }) => { useEffect(() => { const fetchPoiTypData2 = async () => { try { - const response = await fetch("/api/poiTyp"); + const response = await fetch("/api/readPoiTyp"); const data = await response.json(); setPoiTypData2(data); if (data && data.length > 0) { diff --git a/pages/api/locations.js b/pages/api/readLocations.js similarity index 72% rename from pages/api/locations.js rename to pages/api/readLocations.js index 81c910d61..8c5c9a484 100644 --- a/pages/api/locations.js +++ b/pages/api/readLocations.js @@ -1,7 +1,6 @@ -// pages/api/locations.js +// pages/api/readLocations.js import mysql from "mysql"; - const dbConfig = { host: process.env.DB_HOST, user: process.env.DB_USER, @@ -11,7 +10,6 @@ const dbConfig = { }; console.log("my dbconfig: ", dbConfig); export default function handler(req, res) { - const connection = mysql.createConnection(dbConfig); connection.connect((err) => { @@ -27,18 +25,21 @@ export default function handler(req, res) { "SELECT idPoi, description, idPoiTyp, ST_AsText(position) AS position FROM poi", (error, results) => { if (error) { - console.error("Fehler beim Abrufen der API",error); + console.error("Fehler beim Abrufen der API", error); res.status(500).json({ error: "Fehler bei der Abfrage" }); return; } // Wichtig: Senden Sie die Antwort zurück - res.status(200).json(results ); - console.log( "--------------- location.js ---------------","results in location.js : ",results, "---------------------- location.js end ---------------------------"); + res.status(200).json(results); + console.log( + "--------------- location.js ---------------", + "results in location.js : ", + results, + "---------------------- location.js end ---------------------------" + ); connection.end(); } ); }); - - } diff --git a/pages/api/poiTyp.js b/pages/api/readPoiTyp.js similarity index 97% rename from pages/api/poiTyp.js rename to pages/api/readPoiTyp.js index 90a461b45..0553848ae 100644 --- a/pages/api/poiTyp.js +++ b/pages/api/readPoiTyp.js @@ -1,4 +1,4 @@ -// pages/api/poiTyp.js +// pages/api/readPoiTyp.js import mysql from "mysql"; const dbConfig = { diff --git a/pages/index.js b/pages/index.js index 56e6476fa..284b9e8d9 100644 --- a/pages/index.js +++ b/pages/index.js @@ -19,7 +19,7 @@ export default function Home() { }); const loadData = async () => { - const response = await fetch("/api/locations"); + const response = await fetch("/api/readLocations"); const data = await response.json(); setLocations(data); };