using MediatR; using Modules.Account.Application.Gateways; using Modules.Account.Domain.Gateways; namespace Modules.Account.Application.Commands; public class CreateAccountCommand : IRequest { public string Email { get; set; } = default!; public string Password { get; set; } = default!; } public class CreateAccountCommandHandler(IAccountGateway gateway, IPasswordHasher passwordHasher) : IRequestHandler { public async Task Handle(CreateAccountCommand request, CancellationToken cancellationToken) { if (await gateway.IsExists(request.Email)) throw new Exception("Account with the same eamil already exists"); var newAccount = Domain.Entities.Account.Create(request.Email, request.Password, passwordHasher); return await gateway.Create(new Models.Account { Email = newAccount.Email.Value, HashedPassword = newAccount.HashedPassword, }); } }