Rename api/locations to api/readLocations and api/poiTyp to api/readPoiTyp

This commit is contained in:
ISA
2024-05-03 09:26:09 +02:00
parent fb25f3a39d
commit 79c0b4e8cf
5 changed files with 13 additions and 12 deletions

View File

@@ -332,7 +332,7 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
useEffect(() => { useEffect(() => {
const fetchPoiTypData = async () => { const fetchPoiTypData = async () => {
try { try {
const response = await fetch("/api/poiTyp"); const response = await fetch("/api/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) {

View File

@@ -11,7 +11,7 @@ const ShowAddStationPopup = ({ map, latlng }) => {
useEffect(() => { useEffect(() => {
const fetchPoiTypData2 = async () => { const fetchPoiTypData2 = async () => {
try { try {
const response = await fetch("/api/poiTyp"); const response = await fetch("/api/readPoiTyp");
const data = await response.json(); const data = await response.json();
setPoiTypData2(data); setPoiTypData2(data);
if (data && data.length > 0) { if (data && data.length > 0) {

View File

@@ -1,7 +1,6 @@
// pages/api/locations.js // pages/api/readLocations.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,
@@ -11,7 +10,6 @@ const dbConfig = {
}; };
console.log("my dbconfig: ", dbConfig); console.log("my dbconfig: ", dbConfig);
export default function handler(req, res) { export default function handler(req, res) {
const connection = mysql.createConnection(dbConfig); const connection = mysql.createConnection(dbConfig);
connection.connect((err) => { connection.connect((err) => {
@@ -27,18 +25,21 @@ export default function handler(req, res) {
"SELECT idPoi, description, idPoiTyp, ST_AsText(position) AS position FROM poi", "SELECT idPoi, description, idPoiTyp, ST_AsText(position) AS position FROM poi",
(error, results) => { (error, results) => {
if (error) { 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" }); res.status(500).json({ error: "Fehler bei der Abfrage" });
return; return;
} }
// Wichtig: Senden Sie die Antwort zurück // Wichtig: Senden Sie die Antwort zurück
res.status(200).json(results ); res.status(200).json(results);
console.log( "--------------- location.js ---------------","results in location.js : ",results, "---------------------- location.js end ---------------------------"); console.log(
"--------------- location.js ---------------",
"results in location.js : ",
results,
"---------------------- location.js end ---------------------------"
);
connection.end(); connection.end();
} }
); );
}); });
} }

View File

@@ -1,4 +1,4 @@
// pages/api/poiTyp.js // pages/api/readPoiTyp.js
import mysql from "mysql"; import mysql from "mysql";
const dbConfig = { const dbConfig = {

View File

@@ -19,7 +19,7 @@ export default function Home() {
}); });
const loadData = async () => { const loadData = async () => {
const response = await fetch("/api/locations"); const response = await fetch("/api/readLocations");
const data = await response.json(); const data = await response.json();
setLocations(data); setLocations(data);
}; };