diff --git a/src/routers/dashboard.py b/src/routers/dashboard.py index dcba3f5..017bf27 100644 --- a/src/routers/dashboard.py +++ b/src/routers/dashboard.py @@ -368,30 +368,24 @@ async def project_detail( from fastapi import HTTPException raise HTTPException(status_code=404, detail="Project not found") - from_date, to_date = _date_range(from_date, to_date) + # When no date range given, show all-time data for the project + date_filter_given = from_date is not None or to_date is not None + if date_filter_given: + from_date, to_date = _date_range(from_date, to_date) + + stats_where = [DailyStat.user_id == user.id, DailyStat.project_id == project_id] + sessions_where = [Session.user_id == user.id, Session.project_id == project_id] + if date_filter_given: + stats_where += [DailyStat.date >= from_date, DailyStat.date <= to_date] + sessions_where += [Session.date >= from_date, Session.date <= to_date] stats_result = await db.execute( - select(DailyStat) - .where( - DailyStat.user_id == user.id, - DailyStat.project_id == project_id, - DailyStat.date >= from_date, - DailyStat.date <= to_date, - ) - .order_by(DailyStat.date) + select(DailyStat).where(*stats_where).order_by(DailyStat.date) ) stats = stats_result.scalars().all() sessions_result = await db.execute( - select(Session) - .where( - Session.user_id == user.id, - Session.project_id == project_id, - Session.date >= from_date, - Session.date <= to_date, - ) - .order_by(Session.start_at.desc()) - .limit(200) + select(Session).where(*sessions_where).order_by(Session.start_at.desc()).limit(200) ) sessions = sessions_result.scalars().all()