Der Name von POI lesen und in Aktualisierung-Popup einfügen
This commit is contained in:
42
pages/api/getPoiById.js
Normal file
42
pages/api/getPoiById.js
Normal 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`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user