Feature: Welcome-Chips — Termin nur <60 Tage, Übung des Tages als Fallback, async Gassirunde-Bank — SW by-v476, APP_VER 453

This commit is contained in:
rene 2026-04-29 07:34:22 +02:00
parent db386da2c0
commit 4e1e7ca37e
5 changed files with 102 additions and 15 deletions

View file

@ -131,10 +131,12 @@ async def get_welcome_dashboard(dog_id: int, user=Depends(get_current_user)):
).fetchone()
last_diary = dict(last_diary_row) if last_diary_row else None
# Nächster Termin (kein Gewicht)
# Nächster Termin (kein Gewicht, nur innerhalb 60 Tage)
next_appt_row = conn.execute(
"""SELECT bezeichnung, naechstes, typ FROM health
WHERE dog_id=? AND naechstes IS NOT NULL AND naechstes >= date('now')
WHERE dog_id=? AND naechstes IS NOT NULL
AND naechstes >= date('now')
AND naechstes <= date('now', '+60 days')
AND typ != 'gewicht'
ORDER BY naechstes ASC LIMIT 1""",
(dog_id,)
@ -155,12 +157,28 @@ async def get_welcome_dashboard(dog_id: int, user=Depends(get_current_user)):
"SELECT COUNT(*) AS n FROM diary WHERE dog_id=?", (dog_id,)
).fetchone()["n"]
# Tagesübung — stabil pro Tag, rotiert täglich
exercise_count = conn.execute(
"SELECT COUNT(*) AS n FROM training_exercises"
).fetchone()["n"]
daily_exercise = None
if exercise_count:
import datetime as _dt
day_num = (_dt.date.today() - _dt.date(2024, 1, 1)).days
offset = day_num % exercise_count
ex_row = conn.execute(
"SELECT exercise_id, name, kategorie, schwierigkeit FROM training_exercises ORDER BY id LIMIT 1 OFFSET ?",
(offset,)
).fetchone()
daily_exercise = dict(ex_row) if ex_row else None
return {
"random_photo": random_photo,
"last_diary": last_diary,
"next_appointment": next_appointment,
"last_weight": last_weight,
"diary_count": diary_count,
"daily_exercise": daily_exercise,
}