refactor(area): Bereichsaktualisierung von util auf Redux umgestellt

- updateAreaUtil.js entfernt
- updateAreaService, updateAreaThunk, updateAreaSlice eingeführt
- useAreaMarkersLayer nutzt jetzt updateAreaThunk
- MapComponent umgestellt auf Redux-Dispatch
- Version erhöht auf 1.1.182
This commit is contained in:
ISA
2025-05-27 07:55:12 +02:00
parent b6acf719ff
commit 44cb27ce0f
12 changed files with 159 additions and 94 deletions

View File

@@ -0,0 +1,92 @@
// /pages/api/talas_v5_DB/area/readArea.js
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 = ?";
/* let query = `
SELECT
l.name,
l.shortname,
lc.idMaps
FROM
talas_v5.location l
JOIN
talas_v5.location_coordinates lc
ON
l.idlocation = lc.idlocation
WHERE
lc.idMap = ?
`; */
/* let query = `
SELECT * FROM talas_v5.location l JOIN talas_v5.location_coordinates lc ON l.idlocation = lc.idlocation WHERE lc.idMaps=?;
`; */
let query = `
SELECT
l.idlocation,
l.name AS location_name,
lc.idMaps,
a.name AS area_name,
lc.x,
lc.y
FROM
talas_v5.location l
JOIN
talas_v5.location_coordinates lc
ON l.idlocation = lc.idlocation
JOIN
talas_v5.area a
ON l.idarea = a.idarea
WHERE
lc.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, // Prüfe hier auf korrekten Spaltennamen
x: row.x,
y: row.y,
idMaps: row.idMaps,
location_name: row.location_name, // Hinzufügen des Alias aus der SQL-Abfrage
area_name: row.area_name, // Hinzufügen des Alias aus der SQL-Abfrage
}));
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
}
}

View File

@@ -0,0 +1,48 @@
// /pages/api/talas_v5_DB/area/updateArea.js
import getPool from "../../../../utils/mysqlPool";
export default async function handler(req, res) {
console.log("Request erhalten:", req.method, req.body); // Debugging
const pool = getPool();
// Prüfe, ob die Methode PUT ist
if (req.method !== "PUT") {
return res.status(405).json({ error: "Nur PUT Methode erlaubt" });
}
// Daten aus dem Request-Body extrahieren
const { idLocation, idMap, x, y } = req.body;
if (!idLocation || !idMap || x === undefined || y === undefined) {
return res.status(400).json({ error: "Alle Felder (idLocation, idMap, x, y) sind erforderlich" });
}
let connection;
try {
// Verbindung zur Datenbank herstellen
connection = await pool.getConnection();
const query = "UPDATE location_coordinates SET x = ?, y = ? WHERE idLocation = ? AND idMaps = ?";
const [result] = await connection.query(query, [x, y, idLocation, idMap]);
// Erfolgreiche Aktualisierung prüfen
if (result.affectedRows > 0) {
return res.status(200).json({ success: true, message: "Koordinaten erfolgreich aktualisiert" });
} else {
return res.status(404).json({ error: "Kein Eintrag gefunden, der aktualisiert werden konnte" });
}
} catch (error) {
console.error("Fehler beim Aktualisieren der Koordinaten:", error);
return res.status(500).json({ error: "Interner Serverfehler beim Aktualisieren der Koordinaten" });
} finally {
if (connection) {
connection.release();
}
// Sicherheitshalber eine Standardantwort senden, falls keine vorherige Antwort existiert
if (!res.headersSent) {
res.status(500).json({ error: "Keine Antwort vom Server" });
}
}
}