Skip to main content

max / goingson

1.8 KB · 55 lines History Blame Raw
1 use super::{DateTime, Result, UserId, Utc, async_trait};
2
3 /// Aggregated statistics for the dashboard.
4 #[derive(Debug, Clone, serde::Serialize)]
5 pub struct DashboardStats {
6 /// Number of tasks due today.
7 pub tasks_due_today: i64,
8 /// Number of tasks due within the next 7 days.
9 pub tasks_due_this_week: i64,
10 /// Number of overdue tasks.
11 pub overdue_count: i64,
12 /// Number of unread emails.
13 pub unread_emails: i64,
14 /// Number of events in the next 7 days.
15 pub upcoming_events: i64,
16 /// Number of active projects.
17 pub active_projects: i64,
18 /// Top tasks by urgency score.
19 pub high_urgency_tasks: Vec<HighUrgencyTask>,
20 }
21
22 /// A task with high urgency for dashboard display.
23 #[derive(Debug, Clone, serde::Serialize)]
24 pub struct HighUrgencyTask {
25 /// Task ID as string.
26 pub id: String,
27 /// Task description.
28 pub description: String,
29 /// Calculated urgency score.
30 pub urgency: f64,
31 /// Task status.
32 pub status: String,
33 /// Due date if set, formatted as ISO string.
34 pub due: Option<String>,
35 }
36
37 /// Repository for dashboard statistics.
38 #[async_trait]
39 pub trait StatsRepository: Send + Sync {
40 /// Computes aggregated dashboard statistics for a user.
41 ///
42 /// Calendar-day windows (`today_start`, `tomorrow_start`, `week_end`) are
43 /// passed in as UTC instants derived from the user's *local* day, so "due
44 /// today/this week" respect the user's timezone rather than UTC midnights.
45 /// `now` is the reference instant for overdue/upcoming comparisons.
46 async fn get_dashboard_stats(
47 &self,
48 user_id: UserId,
49 now: DateTime<Utc>,
50 today_start: DateTime<Utc>,
51 tomorrow_start: DateTime<Utc>,
52 week_end: DateTime<Utc>,
53 ) -> Result<DashboardStats>;
54 }
55