From 5a56024501665094859f673f6db5210d46a6a182 Mon Sep 17 00:00:00 2001 From: claude-dev Date: Sat, 11 Apr 2026 11:55:35 +0000 Subject: [PATCH] =?UTF-8?q?top=5Farticles=20pro=20Location=20in=20Lagebild?= =?UTF-8?q?-API=20erg=C3=A4nzen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _build_lagebild_response() liefert jetzt Top-3-Artikel (neueste) pro Location für Karten-Popups mit klickbaren Quellen-Links. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/routers/public_api.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/routers/public_api.py b/src/routers/public_api.py index f315d0b..e515342 100644 --- a/src/routers/public_api.py +++ b/src/routers/public_api.py @@ -142,6 +142,30 @@ async def _build_lagebild_response(db, incident_ids: list, primary_id: int) -> d ) locations = [dict(r) for r in await cursor.fetchall()] + # Top-3-Artikel pro Location (neueste zuerst) + cursor = await db.execute( + f"""SELECT al.location_name_normalized as loc_name, + a.headline_de, a.headline, a.source, a.source_url + FROM article_locations al + JOIN articles a ON a.id = al.article_id + WHERE al.incident_id IN ({ids}) + ORDER BY a.published_at DESC""" + ) + loc_articles = {} + for r in await cursor.fetchall(): + r = dict(r) + name = r["loc_name"] + if name not in loc_articles: + loc_articles[name] = [] + if len(loc_articles[name]) < 3: + loc_articles[name].append({ + "headline": r["headline_de"] or r["headline"] or "", + "source": r["source"] or "", + "url": r["source_url"] or "", + }) + for loc in locations: + loc["top_articles"] = loc_articles.get(loc["name"], []) + return { "generated_at": datetime.now(TIMEZONE).isoformat(), "incident": {