Files
poimen-memory/crates/mem-store/src/community_repo.rs
T

46 lines
1.9 KiB
Rust
Raw Normal View History

//! 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<String>;
async fn find_by_id(&self, id: &str) -> Result<Option<Community>>;
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<Vec<Community>>;
async fn search_by_keywords(&self, proj_id: &str, keyword: &str) -> Result<Vec<Community>>;
async fn find_by_project(&self, proj_id: &str) -> Result<Vec<Community>>;
async fn increment_version(&self, id: &str) -> Result<()>;
async fn count(&self, proj_id: &str) -> Result<i64>;
}
pub struct MockCommunityRepo;
#[async_trait]
impl CommunityRepoOps for MockCommunityRepo {
async fn insert(&self, c: &Community) -> Result<String> { Ok(c.id.clone()) }
async fn find_by_id(&self, _id: &str) -> Result<Option<Community>> { 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<Vec<Community>> { Ok(vec![]) }
async fn search_by_keywords(&self, _p: &str, _k: &str) -> Result<Vec<Community>> { Ok(vec![]) }
async fn find_by_project(&self, _p: &str) -> Result<Vec<Community>> { Ok(vec![]) }
async fn increment_version(&self, _id: &str) -> Result<()> { Ok(()) }
async fn count(&self, _p: &str) -> Result<i64> { 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());
}
}