refactor to adapters

This commit is contained in:
2025-12-15 18:34:20 +01:00
parent fc671482c8
commit c817d76092
145 changed files with 906 additions and 361 deletions

View File

@@ -0,0 +1,41 @@
import { EmailAddress } from '../../domain/value-objects/EmailAddress';
import { UserId } from '../../domain/value-objects/UserId';
import { User } from '../../domain/entities/User';
import { IAuthRepository } from '../../domain/repositories/IAuthRepository';
import { IPasswordHashingService } from '../../domain/services/PasswordHashingService';
/**
* Application Use Case: SignupUseCase
*
* Handles user registration.
*/
export class SignupUseCase {
constructor(
private authRepo: IAuthRepository,
private passwordService: IPasswordHashingService
) {}
async execute(email: string, password: string, displayName: string): Promise<User> {
const emailVO = EmailAddress.create(email);
// Check if user already exists
const existingUser = await this.authRepo.findByEmail(emailVO);
if (existingUser) {
throw new Error('User already exists');
}
const hashedPassword = await this.passwordService.hash(password);
const passwordHash = await import('../../domain/value-objects/PasswordHash').then(m => m.PasswordHash.fromHash(hashedPassword));
const userId = UserId.create();
const user = User.create({
id: userId,
displayName,
email: emailVO.value,
passwordHash,
});
await this.authRepo.save(user);
return user;
}
}