api v2.0
This commit is contained in:
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user