refactor(application): strip comments, DRY ownership check + parse_content_type

This commit is contained in:
2026-07-12 04:10:58 +02:00
parent 98a54245b1
commit 9dcd169689
62 changed files with 56 additions and 203 deletions

View File

@@ -5,33 +5,23 @@ use domain::{DomainResult, Email, Password};
use super::commands::RegisterCommand;
use super::deps::AuthDeps;
/// Register a new local user.
///
/// Flow: validate email/password -> check duplicate -> hash password ->
/// create User (first user gets admin) -> save -> publish event -> return User.
pub async fn execute(deps: &AuthDeps, cmd: RegisterCommand) -> DomainResult<User> {
// Validate inputs via domain value objects
let email = Email::new(&cmd.email)?;
let password = Password::new(&cmd.password)?;
// Check for duplicate
if deps.user_query.find_by_email(email.as_ref()).await?.is_some() {
return Err(domain::DomainError::UserAlreadyExists(cmd.email));
}
// Hash password
let hash = deps.auth_service.hash_password(password.as_ref())?;
// Create user; first user gets admin
let mut user = User::new_local(email, hash);
if deps.user_query.count_users().await? == 0 {
user.promote_to_admin();
}
// Persist
deps.user_command.save(&user).await?;
// Publish event
deps.event_publisher
.publish(DomainEvent::UserRegistered {
user_id: user.id(),