diff --git a/VERSION b/VERSION index a899ac6..8535dde 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1160 \ No newline at end of file +1161 \ No newline at end of file diff --git a/backend/routes/routen.py b/backend/routes/routen.py index 0e81704..db57d55 100644 --- a/backend/routes/routen.py +++ b/backend/routes/routen.py @@ -95,6 +95,7 @@ async def list_routes( radius: int = 10000, user = Depends(get_current_user_optional), ): + _uid = user['id'] if user else -1 with db() as conn: rows = conn.execute(""" SELECT r.id, r.user_id, r.name, r.beschreibung, @@ -106,11 +107,13 @@ async def list_routes( json_extract(r.gps_track, '$[0].lat') AS start_lat, json_extract(r.gps_track, '$[0].lon') AS start_lon, json_extract(r.gps_track, '$[#-1].lat') AS end_lat, - json_extract(r.gps_track, '$[#-1].lon') AS end_lon + json_extract(r.gps_track, '$[#-1].lon') AS end_lon, + (SELECT COUNT(*) FROM route_walks w WHERE w.route_id=r.id AND w.user_id=?) AS my_walk_count, + (SELECT MAX(walked_at) FROM route_walks w WHERE w.route_id=r.id AND w.user_id=?) AS my_last_walked FROM routes r LEFT JOIN users u ON u.id = r.user_id ORDER BY r.created_at DESC - """).fetchall() + """, (_uid, _uid)).fetchall() result = [] for row in rows: @@ -492,7 +495,13 @@ async def record_walk(route_id: int, body: WalkRecord, user=Depends(get_current_ ) update_streak(uid, conn) new_badges = check_and_award(uid, conn) - return {"ok": True, "new_badges": new_badges} + total_km = conn.execute( + "SELECT ROUND(" + " COALESCE((SELECT SUM(distanz_km) FROM routes WHERE user_id=? AND is_valid=1),0) +" + " COALESCE((SELECT SUM(walked_km) FROM route_walks WHERE user_id=?),0), 1)", + (uid, uid) + ).fetchone()[0] + return {"ok": True, "new_badges": new_badges, "total_km": total_km} # ------------------------------------------------------------------ diff --git a/backend/static/index.html b/backend/static/index.html index 1689eef..950d38a 100644 --- a/backend/static/index.html +++ b/backend/static/index.html @@ -86,14 +86,14 @@