first commit

This commit is contained in:
ISA
2024-04-15 10:37:53 +02:00
commit afee410333
736 changed files with 110561 additions and 0 deletions

37
pages/api/addLocation.js Normal file
View File

@@ -0,0 +1,37 @@
// pages/api/addLocation.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 === "POST") {
const { name, type, latitude, longitude } = req.body;
const connection = mysql.createConnection(dbConfig);
// Nutze ST_GeomFromText, um den Punkt zu erzeugen
const query =
"INSERT INTO poi (description, idPoiTyp, position) VALUES (?, ?, ST_GeomFromText(?))";
const point = `POINT(${longitude} ${latitude})`; // Achte auf die Reihenfolge: Längengrad (Longitude), Breitengrad (Latitude)
const values = [name, type, point];
connection.query(query, values, (error, results) => {
connection.end();
if (error) {
console.error("Fehler beim Einfügen des Standorts:", error);
return res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
}
res.status(200).json({ id: results.insertId, message: "Standort erfolgreich hinzugefügt" });
});
} else {
res.setHeader("Allow", ["POST"]);
res.status(405).end(`Method ${req.method} Not Allowed`);
}
}