Refactor all code
This commit is contained in:
@@ -8,9 +8,7 @@ using PyroFetes.Specifications.Users;
|
||||
|
||||
namespace PyroFetes.Endpoints.Users;
|
||||
|
||||
public class CreateUserEndpoint(
|
||||
UsersRepository usersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<CreateUserDto, GetUserDto>
|
||||
public class CreateUserEndpoint(UsersRepository usersRepository) : Endpoint<CreateUserDto, GetUserDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
@@ -20,17 +18,17 @@ public class CreateUserEndpoint(
|
||||
|
||||
public override async Task HandleAsync(CreateUserDto req, CancellationToken ct)
|
||||
{
|
||||
User? ckeckName = await usersRepository.FirstOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct);
|
||||
|
||||
if (ckeckName != null)
|
||||
User? ckeckName = await usersRepository.SingleOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct);
|
||||
|
||||
if (ckeckName is not null)
|
||||
{
|
||||
await Send.StringAsync("Ce nom d'utilisateur existe déjà.",409, cancellation: ct);
|
||||
await Send.StringAsync("Ce nom d'utilisateur existe déjà.", 400, cancellation: ct);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
string? salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next();
|
||||
|
||||
User user = new User()
|
||||
|
||||
User user = new()
|
||||
{
|
||||
Name = req.Name,
|
||||
Password = BCrypt.Net.BCrypt.HashPassword(req.Password + salt),
|
||||
@@ -38,9 +36,8 @@ public class CreateUserEndpoint(
|
||||
Email = req.Email,
|
||||
Fonction = req.Fonction
|
||||
};
|
||||
|
||||
|
||||
await usersRepository.AddAsync(user, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetUserDto>(user), ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user