refactor(ports): CQRS split — UserRepository = UserReader + UserWriter supertrait

This commit is contained in:
2026-05-15 13:43:43 +02:00
parent a902154777
commit 8ed7f3d5bc
17 changed files with 113 additions and 97 deletions

View File

@@ -45,7 +45,7 @@ pub struct TestStore {
}
#[async_trait]
impl UserRepository for TestStore {
impl UserReader for TestStore {
async fn find_by_id(&self, id: &UserId) -> Result<Option<User>, DomainError> {
Ok(self
.users
@@ -73,6 +73,22 @@ impl UserRepository for TestStore {
.find(|u| u.email.as_str() == email.as_str())
.cloned())
}
async fn list_with_stats(&self) -> Result<Vec<UserSummary>, DomainError> {
Ok(vec![])
}
async fn count(&self) -> Result<i64, DomainError> {
Ok(self
.users
.lock()
.unwrap()
.iter()
.filter(|u| u.local)
.count() as i64)
}
}
#[async_trait]
impl UserWriter for TestStore {
async fn save(&self, user: &User) -> Result<(), DomainError> {
let mut g = self.users.lock().unwrap();
g.retain(|u| u.id != user.id);
@@ -103,18 +119,6 @@ impl UserRepository for TestStore {
}
Ok(())
}
async fn list_with_stats(&self) -> Result<Vec<UserSummary>, DomainError> {
Ok(vec![])
}
async fn count(&self) -> Result<i64, DomainError> {
Ok(self
.users
.lock()
.unwrap()
.iter()
.filter(|u| u.local)
.count() as i64)
}
}
#[async_trait]