diff --git a/.gitignore b/.gitignore index ac307b1..33654e0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ env/ .env .ipynb_checkpoints/ logs/app.log +*.db +.vscode/ + diff --git a/api/dashboard.py b/api/dashboard.py index e6eda35..f1aec34 100644 --- a/api/dashboard.py +++ b/api/dashboard.py @@ -1,7 +1,3 @@ -# will require edits to the frontend to ensure user data persists: - # src/components/DashboardLanding/DashboardLanding.tsx - # src/components/ProfileAvatar/ProfileAvatar.tsx -# alternatively, find edited files on planner board > 'Add Endpoint for the Dashboard'. import sys from flask import Blueprint, jsonify @@ -9,6 +5,8 @@ from flask_cors import CORS from datetime import datetime, timezone +from models.body_insight import BodyInsight +from models.activity import Activity # Create the Blueprint for dashboard dashboard_bp = Blueprint('dashboard', __name__, url_prefix='/api/dashboard') @@ -20,21 +18,37 @@ def get_dashboard_data(): user_id = 1 # Temporary fixed user user = UserProfile.query.filter_by(id=user_id).first() - if user: - current_utc_time = datetime.now(timezone.utc) - vo2_max = 45 # placeholder for further implementation - - # DEBUG LOGGING - print(f"User fetched: {user.as_dict()}", file=sys.stderr) - - return jsonify({ - 'name': user.name, - 'account': user.account, - 'birthDate': user.birthDate, - 'gender': user.gender, - 'avatar': user.avatar, - 'lastLogin': current_utc_time.isoformat(), - 'vo2Max': vo2_max - }) - - return jsonify({'message': 'User not found'}), 404 + if not user: + return jsonify({'message': 'User not found'}), 404 + + # Find latest activity for this user + latest_activity = ( + Activity.query + .filter_by(user_id=user_id) + .order_by(Activity.begin_time.desc()) + .first() + ) + + # Default vo2_max if no data found + vo2_max = None + + if latest_activity: + body_insight = BodyInsight.query.filter_by(activity_id=latest_activity.id).first() + if body_insight: + vo2_max = body_insight.vo2_max + + current_utc_time = datetime.now(timezone.utc) + + # DEBUG LOGGING + print(f"User fetched: {user.as_dict()}", file=sys.stderr) + print(f"VO2 Max fetched: {vo2_max}", file=sys.stderr) + + return jsonify({ + 'name': user.name, + 'account': user.account, + 'birthDate': user.birthDate, + 'gender': user.gender, + 'avatar': user.avatar, + 'lastLogin': current_utc_time.isoformat(), + 'vo2Max': vo2_max # Can be None if no data found + }) \ No newline at end of file