Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ env/
.env
.ipynb_checkpoints/
logs/app.log
*.db
.vscode/

58 changes: 36 additions & 22 deletions api/dashboard.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# 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
from models.user import db, UserProfile
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')

Expand All @@ -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
})