Files
FACULTATE-HEALTHCARE_MANAGER/backend/Application/Endpoints/Pacients/Registration/PacientRegistrationHandler.cs
T
ElenitaMLG 55eaa0d53a Backend Pacients, Doctors and MedicalHistory endpoints
- added for Pacients:
POST: /register
POST: /login
POST: /reset_password
PUT: /profile
DELETE: /profile

- added for Doctors:
POST: /register
POST: /login
POST: /reset_password
PUT: /profile
DELETE: /profile

- added for MedicalHistories:
POST: /:id (only by pacient) - done
GET: /:id (only by pacient) - done
PUT: /:id (only by doctor) - done
PUT /grand_access - TODO
2024-04-07 00:23:13 +03:00

49 lines
1.4 KiB
C#

using Application.Endpoints.Pacients.Login;
using Application.Services.Database;
using Core.Entities;
namespace Application.Endpoints.Pacients.Registration;
public class PacientRegistrationHandler
{
private readonly IPacientRepository _pacientRepository;
public PacientRegistrationHandler(IPacientRepository pacientRepository)
{
_pacientRepository = pacientRepository;
}
public async Task<BaseResponse> Handle(PacientRegistrationDto registrationDTO)
{
var validation = new PacientRegistrationValidation(_pacientRepository);
var validationResult = await validation.ValidateAsync(registrationDTO);
if (!validationResult.IsValid)
{
var errorMessage = validationResult.Errors.Select(e => e.ErrorMessage).ToList();
return new BaseResponse
{
Success = false,
Message = string.Join(", ", errorMessage),
Data = null
};
}
var pacient = new Pacient
{
Email = registrationDTO.Email,
Password = registrationDTO.Password,
Name = registrationDTO.Name
};
await _pacientRepository.AddAsync(pacient);
return new BaseResponse
{
Success = true,
Message = "Pacient registered successfully",
Data = pacient // Be careful with sending sensitive data like Passwords
};
}
}