agtrace_runtime/ops/
project.rs

1use agtrace_index::Database;
2use anyhow::Result;
3
4#[derive(Debug, Clone)]
5pub struct ProjectInfo {
6    pub hash: String,
7    pub root_path: Option<String>,
8    pub session_count: usize,
9    pub last_scanned: Option<String>,
10}
11
12pub struct ProjectService<'a> {
13    db: &'a Database,
14}
15
16impl<'a> ProjectService<'a> {
17    pub fn new(db: &'a Database) -> Self {
18        Self { db }
19    }
20
21    pub fn list_projects(&self) -> Result<Vec<ProjectInfo>> {
22        let projects = self.db.list_projects()?;
23        let mut summaries = Vec::new();
24        for project in projects {
25            let session_count = self.db.count_sessions_for_project(project.hash.as_str())?;
26            summaries.push(ProjectInfo {
27                hash: project.hash.to_string(),
28                root_path: project.root_path,
29                session_count,
30                last_scanned: project.last_scanned_at,
31            });
32        }
33        Ok(summaries)
34    }
35}