ändern der Gebäudebeschriftung

This commit is contained in:
Cay 2026-03-13 08:05:26 +00:00
parent e3af69cd0c
commit 394f156cdd
3 changed files with 48 additions and 4 deletions

27
app.js
View File

@ -121,6 +121,33 @@ app.get("/api/building/:id", async (req, res) => {
}
});
app.get("/api/buildings", async (req, res) => {
const userId = req.session.user.id;
try {
const [rows] = await db.query(
`
SELECT
b.id,
b.name,
b.description,
b.history,
ub.level,
ub.points
FROM buildings b
LEFT JOIN user_buildings ub
ON ub.building_id = b.id AND ub.user_id = ?
`,
[userId],
);
res.json(rows);
} catch (err) {
console.error(err);
res.status(500).json({ error: "DB Fehler" });
}
});
/* ========================
Body Parser
======================== */

17
public/js/building.js Normal file
View File

@ -0,0 +1,17 @@
fetch("/api/buildings")
.then((res) => res.json())
.then((buildings) => {
buildings.forEach((building) => {
const element = document.querySelector(
`.building[data-id="${building.id}"]`,
);
if (!element) return;
const title = element.querySelector("title");
if (title) {
title.textContent = building.name;
}
});
});

View File

@ -41,8 +41,8 @@
class="map-overlay"
>
<!-- 1 -->
<a href="/building/1" class="building">
<title>Pforte Links</title>
<a href="/building/1" class="building" data-id="1">
<title></title>
<polygon
class="area"
points="276,185 387,192 379,382 287,365 284,364"
@ -50,8 +50,8 @@
</a>
<!-- 2 -->
<a href="/building/2" class="building">
<title>Burg</title>
<a href="/building/2" class="building" data-id="2">
<title></title>
<polygon
class="area"
points="777,365 865,238 969,263 1039,347 1071,419 1095,531 925,479 776,497"