finalizare 1.0

This commit is contained in:
andrei-mihnea-cerbu
2024-05-21 12:10:53 +03:00
parent f7795f7519
commit 1cc1d34003
11268 changed files with 2102399 additions and 10909 deletions
@@ -0,0 +1,46 @@
using Application.Services.Database.PostgreSQL;
using Application.Services.HashingAlgorithms;
namespace Application.Endpoints.Patients.ModifyPatient;
public class ModifyPatientHandler(
IHashingAlgorithms hashingAlgorithms,
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(hashingAlgorithms.Sha256Algorithm(request.Password));
await patientRepository.UpdateAsync(newPatient, token);
return new BaseResponse
{
StatusCode = HttpStatusCodes.NoContent,
Message = null,
Data = null
};
}
}