Der Name von POI lesen und in Aktualisierung-Popup einfügen

This commit is contained in:
ISA
2024-05-22 12:18:00 +02:00
parent 3bd491e825
commit 211192c3f0
3 changed files with 120 additions and 9 deletions

42
pages/api/getPoiById.js Normal file
View File

@@ -0,0 +1,42 @@
// pages/api/getPoiById.js
import mysql from "mysql";
const dbConfig = {
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
port: process.env.DB_PORT,
};
export default function handler(req, res) {
if (req.method === "GET") {
const { idPoi } = req.query;
const connection = mysql.createConnection(dbConfig);
connection.connect((err) => {
if (err) {
console.error("Fehler beim Verbinden:", err.stack);
return res
.status(500)
.json({ error: "Verbindungsfehler zur Datenbank" });
}
const query = "SELECT description FROM poi WHERE idPoi = ?";
connection.query(query, [idPoi], (error, results) => {
connection.end();
if (error) {
console.error("Fehler bei der Abfrage:", error);
return res.status(500).json({ error: "Fehler bei der Abfrage" });
}
if (results.length === 0) {
return res.status(404).json({ error: "POI nicht gefunden" });
}
res.status(200).json(results[0]);
});
});
} else {
res.setHeader("Allow", ["GET"]);
res.status(405).end(`Method ${req.method} Not Allowed`);
}
}