WIP: Bereich wird angezeigt, aber da ist noch ein Bug, Talas Marker erscheint trotz Checkbox ausgecheckt
This commit is contained in:
51
pages/api/talas_v5_DB/bereich/readBereich.js
Normal file
51
pages/api/talas_v5_DB/bereich/readBereich.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const pool = getPool(); // Singleton-Pool verwenden
|
||||
|
||||
if (req.method !== "GET") {
|
||||
return res.status(405).json({ error: "Nur GET Methode erlaubt" });
|
||||
}
|
||||
|
||||
const { m: idMaps, idLocation } = req.query; // URL-Parameter "m" und "idLocation"
|
||||
|
||||
if (!idMaps) {
|
||||
return res.status(400).json({ error: "idMaps (Parameter 'm') ist erforderlich" });
|
||||
}
|
||||
|
||||
let query = "SELECT * FROM location_coordinates WHERE idMaps = ?";
|
||||
const queryParams = [idMaps];
|
||||
|
||||
if (idLocation) {
|
||||
query += " AND idLocation = ?";
|
||||
queryParams.push(idLocation);
|
||||
}
|
||||
|
||||
let connection;
|
||||
|
||||
try {
|
||||
connection = await pool.getConnection(); // Verbindung aus dem Pool holen
|
||||
|
||||
// SQL-Abfrage ausführen
|
||||
const [results] = await connection.query(query, queryParams);
|
||||
|
||||
if (results.length > 0) {
|
||||
// Ergebnisse formatieren und zurückgeben
|
||||
const formattedResults = results.map((row) => ({
|
||||
idLocation: row.idLocation,
|
||||
x: row.x,
|
||||
y: row.y,
|
||||
idMaps: row.idMaps,
|
||||
}));
|
||||
|
||||
res.status(200).json(formattedResults);
|
||||
} else {
|
||||
res.status(404).json({ error: "Keine Koordinaten gefunden" });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Abrufen der Koordinaten:", error);
|
||||
res.status(500).json({ error: "Interner Serverfehler beim Abrufen der Koordinaten" });
|
||||
} finally {
|
||||
if (connection) connection.release(); // Verbindung in den Pool zurückgeben
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user