Files
FACULTATE-HEALTHCARE_MANAGER/backend/Application/Endpoints/Patients/ModifyPatient/PatientProfileHandler.cs
T
2024-05-30 15:40:13 +03:00

46 lines
1.5 KiB
C#

using Application.Services.Database.PostgreSQL;
using Application.Services.Encryption;
namespace Application.Endpoints.Patients.ModifyPatient;
public class ModifyPatientHandler(
IEncryptionService encryptionService,
IPatientRepository patientRepository,
IDoctorRepository doctorRepository,
IAdminRepository adminRepository
)
{
public async Task<BaseResponse> Handle(ModifyPatientCommand request, CancellationToken token)
{
var validation = new PatientProfileValidator(patientRepository, doctorRepository, adminRepository);
var validationResult = await validation.ValidateAsync(request, token);
if (!validationResult.IsValid)
{
var firstError = validationResult.Errors.FirstOrDefault();
var errorCode = int.TryParse(firstError.ErrorCode, out var code) ? code : -1;
var errorMessage = firstError.ErrorMessage;
return new BaseResponse
{
StatusCode = errorCode,
Message = errorMessage,
Data = null
};
}
var newPatient = await patientRepository.GetByIdAsync(request.Id, token);
newPatient.SetName(request.Name);
newPatient.SetEmail(request.Email);
newPatient.SetPassword(encryptionService.Sha256Algorithm(request.Password));
await patientRepository.UpdateAsync(newPatient, token);
return new BaseResponse
{
StatusCode = HttpStatusCodes.NoContent,
Message = null,
Data = null
};
}
}