Sprint 15: Zeitzone-Fix, Gewichts-Sync, Öffnungszeiten, KI-Bericht, POI-Moderation — SW by-v432, APP_VER 411
- client_time: Browser-Lokalzeit bei allen Creates mitschicken (Tagebuch, Notizen, Forum, Verlorener Hund, Routen) — kein UTC-Versatz mehr bei Einträgen - Gewicht-Sync: health typ=gewicht schreibt dogs.gewicht_kg, einmalige Migration - Praxen: opening_hours + lat/lon/osm_id in tieraerzte-Tabelle, OSM-Nearby-Lookup, Öffnungszeiten in Karte und Detailansicht - KI-Gesundheitsbericht: alle 2 Wochen automatisch, ki_health_reports-Tabelle, Frontend-Banner mit Archiv (letzten 5 Berichte) - POI-Korrekturen: User schlägt Öffnungszeiten-Änderung vor, Moderatoren-Tab genehmigt/lehnt ab, user_edited-Flag schützt vor Overpass-Überschreibung - timeutils.py: safe_client_time() zentral für alle Routen
This commit is contained in:
parent
679dbdd862
commit
06bd8525ed
21 changed files with 724 additions and 75 deletions
|
|
@ -75,6 +75,18 @@ class HealthUpdate(BaseModel):
|
|||
# ------------------------------------------------------------------
|
||||
# Hilfsfunktionen
|
||||
# ------------------------------------------------------------------
|
||||
def _sync_gewicht(conn, dog_id: int):
|
||||
"""Aktualisiert dogs.gewicht_kg auf den neuesten Gewichtseintrag (nach datum)."""
|
||||
conn.execute(
|
||||
"""UPDATE dogs SET gewicht_kg = (
|
||||
SELECT wert FROM health
|
||||
WHERE dog_id=? AND typ='gewicht' AND wert IS NOT NULL
|
||||
ORDER BY datum DESC, id DESC LIMIT 1
|
||||
) WHERE id=?""",
|
||||
(dog_id, dog_id)
|
||||
)
|
||||
|
||||
|
||||
def _check_dog_owner(conn, dog_id: int, user_id: int):
|
||||
dog = conn.execute(
|
||||
"SELECT id FROM dogs WHERE id=? AND user_id=?", (dog_id, user_id)
|
||||
|
|
@ -160,6 +172,8 @@ async def create_health(dog_id: int, data: HealthCreate,
|
|||
(dog_id,)
|
||||
).fetchone()
|
||||
media_map = _fetch_media_items(conn, [row["id"]])
|
||||
if data.typ == 'gewicht':
|
||||
_sync_gewicht(conn, dog_id)
|
||||
return _entry_with_media(row, media_map)
|
||||
|
||||
|
||||
|
|
@ -186,6 +200,8 @@ async def update_health(dog_id: int, entry_id: int, data: HealthUpdate,
|
|||
conn.execute(f"UPDATE health SET {set_clause} WHERE id=?", values)
|
||||
row = conn.execute("SELECT * FROM health WHERE id=?", (entry_id,)).fetchone()
|
||||
media_map = _fetch_media_items(conn, [entry_id])
|
||||
if row["typ"] == 'gewicht':
|
||||
_sync_gewicht(conn, dog_id)
|
||||
return _entry_with_media(row, media_map)
|
||||
|
||||
|
||||
|
|
@ -197,11 +213,14 @@ async def delete_health(dog_id: int, entry_id: int, user=Depends(get_current_use
|
|||
with db() as conn:
|
||||
_check_dog_owner(conn, dog_id, user["id"])
|
||||
entry = conn.execute(
|
||||
"SELECT id FROM health WHERE id=? AND dog_id=?", (entry_id, dog_id)
|
||||
"SELECT id, typ FROM health WHERE id=? AND dog_id=?", (entry_id, dog_id)
|
||||
).fetchone()
|
||||
if not entry:
|
||||
raise HTTPException(404, "Eintrag nicht gefunden.")
|
||||
was_gewicht = entry["typ"] == 'gewicht'
|
||||
conn.execute("DELETE FROM health WHERE id=?", (entry_id,))
|
||||
if was_gewicht:
|
||||
_sync_gewicht(conn, dog_id)
|
||||
return None
|
||||
|
||||
|
||||
|
|
@ -431,3 +450,18 @@ async def ki_zusammenfassung(dog_id: int, user=Depends(get_current_user)):
|
|||
raise HTTPException(402, str(e))
|
||||
except KIUnavailableError as e:
|
||||
raise HTTPException(503, str(e))
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# GET /api/dogs/{dog_id}/health/ki-berichte
|
||||
# ------------------------------------------------------------------
|
||||
@router.get("/{dog_id}/health/ki-berichte")
|
||||
async def list_ki_berichte(dog_id: int, user=Depends(get_current_user)):
|
||||
with db() as conn:
|
||||
_check_dog_owner(conn, dog_id, user["id"])
|
||||
rows = conn.execute(
|
||||
"""SELECT id, bericht, erstellt_at FROM ki_health_reports
|
||||
WHERE dog_id=? ORDER BY erstellt_at DESC LIMIT 5""",
|
||||
(dog_id,)
|
||||
).fetchall()
|
||||
return [dict(r) for r in rows]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue