metis_docs_tui/services/
sync.rs1use anyhow::Result;
2use metis_core::{application::Application, dal::Database};
3use std::path::PathBuf;
4
5pub struct SyncService {
7 workspace_dir: PathBuf,
8}
9
10impl SyncService {
11 pub fn new(workspace_dir: PathBuf) -> Self {
12 Self { workspace_dir }
13 }
14
15 pub async fn sync_database(&self) -> Result<()> {
16 let db_path = self.workspace_dir.join("metis.db");
17 let db = Database::new(&db_path.to_string_lossy())
18 .map_err(|e| anyhow::anyhow!("Database error: {}", e))?;
19 let app = Application::new(db);
20
21 match app.sync_directory(&self.workspace_dir).await {
22 Ok(_) => Ok(()),
23 Err(e) => Err(anyhow::anyhow!("Sync failed: {}", e)),
24 }
25 }
26}