This commit is contained in:
andrei-mihnea-cerbu
2024-04-08 00:03:24 +03:00
parent 2ccec617a5
commit b48d5ee19e
168 changed files with 2877 additions and 1146 deletions
@@ -1,5 +1,5 @@
using Application.Endpoints.Doctors.Login;
using Application.Services.Database;
using Application.Services.Database;
using Application.Services.HashingAlgorithms;
using Core.Entities;
namespace Application.Endpoints.Doctors.Registration;
@@ -7,10 +7,12 @@ namespace Application.Endpoints.Doctors.Registration;
public class DoctorRegistrationHandler
{
private readonly IDoctorRepository _doctorRepository;
private readonly IHashingAlgorithms _hashingAlgorithms;
public DoctorRegistrationHandler(IDoctorRepository doctorRepository)
public DoctorRegistrationHandler(IDoctorRepository doctorRepository, IHashingAlgorithms hashingAlgorithms)
{
_doctorRepository = doctorRepository;
_hashingAlgorithms = hashingAlgorithms;
}
public async Task<BaseResponse> Handle(DoctorRegistrationDto registrationDTO)
@@ -20,30 +22,31 @@ public class DoctorRegistrationHandler
if (!validationResult.IsValid)
{
var errorMessage = validationResult.Errors.Select(e => e.ErrorMessage).ToList();
var firstError = validationResult.Errors.FirstOrDefault();
var errorCode = int.TryParse(firstError.ErrorCode, out var code) ? code : -1;
var errorMessage = firstError.ErrorMessage;
return new BaseResponse
{
Success = false,
Message = string.Join(", ", errorMessage),
StatusCode = errorCode,
Message = errorMessage,
Data = null
};
}
var doctor = new Doctor
{
Email = registrationDTO.Email,
Password = registrationDTO.Password,
Name = registrationDTO.Name,
Description = registrationDTO.Description
};
var doctor = new Doctor();
doctor.SetEmail(registrationDTO.Email);
doctor.SetPassword(_hashingAlgorithms.SHA256Algorithm(registrationDTO.Password));
doctor.SetName(registrationDTO.Name);
doctor.SetDescription(registrationDTO.Description);
await _doctorRepository.AddAsync(doctor);
return new BaseResponse
{
Success = true,
StatusCode = HttpStatusCodes.Created,
Message = "Doctor registered successfully",
Data = doctor // Be careful with sending sensitive data like Passwords
Data = null
};
}
}
}