domain: add Identity & Access ports (UserRepo, RoleRepo, GroupRepo, EventPublisher)

This commit is contained in:
2026-05-31 03:20:22 +02:00
parent 656da7e945
commit cebb4cdaf1
9 changed files with 64 additions and 10 deletions

View File

@@ -0,0 +1,7 @@
use async_trait::async_trait;
use crate::{errors::DomainError, events::DomainEvent};
#[async_trait]
pub trait EventPublisher: Send + Sync {
async fn publish(&self, event: DomainEvent) -> Result<(), DomainError>;
}

View File

@@ -0,0 +1,10 @@
use async_trait::async_trait;
use crate::{entities::Group, errors::DomainError, value_objects::SystemId};
#[async_trait]
pub trait GroupRepository: Send + Sync {
async fn find_by_id(&self, id: &SystemId) -> Result<Option<Group>, DomainError>;
async fn find_by_user(&self, user_id: &SystemId) -> Result<Vec<Group>, DomainError>;
async fn save(&self, group: &Group) -> Result<(), DomainError>;
async fn delete(&self, id: &SystemId) -> Result<(), DomainError>;
}

View File

@@ -1,7 +1,13 @@
mod auth;
mod event_publisher;
mod group_repo;
mod role_repo;
mod storage;
mod user_repo;
pub use auth::{PasswordHasher, TokenIssuer};
pub use event_publisher::EventPublisher;
pub use group_repo::GroupRepository;
pub use role_repo::RoleRepository;
pub use storage::{DataStream, StoragePort, StorageReader, StorageWriter};
pub use user_repo::UserRepository;

View File

@@ -0,0 +1,11 @@
use async_trait::async_trait;
use crate::{entities::Role, errors::DomainError, value_objects::SystemId};
#[async_trait]
pub trait RoleRepository: Send + Sync {
async fn find_by_id(&self, id: &SystemId) -> Result<Option<Role>, DomainError>;
async fn find_by_name(&self, name: &str) -> Result<Option<Role>, DomainError>;
async fn find_defaults(&self) -> Result<Vec<Role>, DomainError>;
async fn save(&self, role: &Role) -> Result<(), DomainError>;
async fn delete(&self, id: &SystemId) -> Result<(), DomainError>;
}

View File

@@ -5,6 +5,7 @@ use crate::{entities::User, errors::DomainError, value_objects::{Email, SystemId
pub trait UserRepository: Send + Sync {
async fn find_by_id(&self, id: &SystemId) -> Result<Option<User>, DomainError>;
async fn find_by_email(&self, email: &Email) -> Result<Option<User>, DomainError>;
async fn find_by_username(&self, username: &str) -> Result<Option<User>, DomainError>;
async fn save(&self, user: &User) -> Result<(), DomainError>;
async fn delete(&self, id: &SystemId) -> Result<(), DomainError>;
}