//! Community repository - trait-based interface use anyhow::Result; use async_trait::async_trait; use mem_core::Community; /// Community operations trait #[async_trait] pub trait CommunityRepoOps: Send + Sync { async fn insert(&self, community: &Community) -> Result; async fn find_by_id(&self, id: &str) -> Result>; async fn update_summary(&self, id: &str, summary: &str, keywords: &[String], emb: Option<&[f32]>) -> Result<()>; async fn update_counts(&self, id: &str) -> Result<()>; async fn find_stale(&self, max_age_hrs: i64, limit: i32) -> Result>; async fn search_by_keywords(&self, proj_id: &str, keyword: &str) -> Result>; async fn find_by_project(&self, proj_id: &str) -> Result>; async fn increment_version(&self, id: &str) -> Result<()>; async fn count(&self, proj_id: &str) -> Result; } pub struct MockCommunityRepo; #[async_trait] impl CommunityRepoOps for MockCommunityRepo { async fn insert(&self, c: &Community) -> Result { Ok(c.id.clone()) } async fn find_by_id(&self, _id: &str) -> Result> { Ok(None) } async fn update_summary(&self, _id: &str, _s: &str, _k: &[String], _e: Option<&[f32]>) -> Result<()> { Ok(()) } async fn update_counts(&self, _id: &str) -> Result<()> { Ok(()) } async fn find_stale(&self, _a: i64, _l: i32) -> Result> { Ok(vec![]) } async fn search_by_keywords(&self, _p: &str, _k: &str) -> Result> { Ok(vec![]) } async fn find_by_project(&self, _p: &str) -> Result> { Ok(vec![]) } async fn increment_version(&self, _id: &str) -> Result<()> { Ok(()) } async fn count(&self, _p: &str) -> Result { Ok(0) } } #[cfg(test)] mod tests { use super::*; #[tokio::test] async fn test_mock_community_repo() { let repo = MockCommunityRepo; assert!(repo.count("test").await.is_ok()); } }