serviciu email done

This commit is contained in:
andrei-mihnea-cerbu
2024-04-09 03:03:44 +03:00
parent 0d03c0ea43
commit 9977a9b5f5
63 changed files with 135 additions and 17 deletions
+12 -1
View File
@@ -5,6 +5,7 @@ using Application.Endpoints.Doctors.Registration;
using Application.Endpoints.Doctors.ResetPassword;
using Application.Services.Database.MongoDB;
using Application.Services.Database.PostgreSQL;
using Application.Services.Email;
using Application.Services.HashingAlgorithms;
using Application.Services.Jwt;
using Core.Entities;
@@ -20,14 +21,16 @@ public class DoctorsController : ControllerBase
private readonly IDoctorRepository _database;
private readonly IHashingAlgorithms _hashingAlgorithms;
private readonly IJwtService _jwtService;
private readonly IEmailService _emailService;
public DoctorsController(IDoctorRepository database, IHashingAlgorithms hashingAlgorithms,
IJwtService jwtService, IAppointmentsMongoDbService appointmentsMongoDbService)
IJwtService jwtService, IAppointmentsMongoDbService appointmentsMongoDbService, IEmailService emailService)
{
_database = database;
_hashingAlgorithms = hashingAlgorithms;
_jwtService = jwtService;
_appointmentsMongoDbService = appointmentsMongoDbService;
_emailService = emailService;
}
[HttpPost("register")]
@@ -35,6 +38,14 @@ public class DoctorsController : ControllerBase
{
var handler = new DoctorRegistrationHandler(_database, _hashingAlgorithms);
var response = await handler.Handle(doctorRegistrationDto).ConfigureAwait(false);
if (response.StatusCode < HttpStatusCodes.BadRequest)
{
var body = _emailService.GenerateCredentialsEmailBody(
doctorRegistrationDto.Email, doctorRegistrationDto.Password);
await _emailService.SendEmailAsync(doctorRegistrationDto.Email, "Successful registration!", body);
}
return StatusCode(response.StatusCode, response);
}
+13 -1
View File
@@ -5,7 +5,9 @@ using Application.Endpoints.Patients.Registration;
using Application.Endpoints.Patients.ResetPassword;
using Application.Services.Database.PostgreSQL;
using Application.Services.HashingAlgorithms;
using Application.Services.Email;
using Application.Services.Jwt;
using Core.Entities;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers;
@@ -18,14 +20,16 @@ public class PatientsController : ControllerBase
private readonly IJwtService _jwtService;
private readonly IMedicalHistoryRepository _medicalHistory;
private readonly IPatientRepository _patientRepository;
private readonly IEmailService _emailService;
public PatientsController(IPatientRepository patientRepository, IHashingAlgorithms hashingAlgorithms,
IJwtService jwtService, IMedicalHistoryRepository medicalHistory)
IJwtService jwtService, IMedicalHistoryRepository medicalHistory, IEmailService emailService)
{
_patientRepository = patientRepository;
_hashingAlgorithms = hashingAlgorithms;
_jwtService = jwtService;
_medicalHistory = medicalHistory;
_emailService = emailService;
}
[HttpGet]
@@ -97,6 +101,14 @@ public class PatientsController : ControllerBase
{
var handler = new PatientRegistrationHandler(_patientRepository, _hashingAlgorithms);
var response = await handler.Handle(patientRegistrationDto).ConfigureAwait(false);
if (response.StatusCode < HttpStatusCodes.BadRequest)
{
var body = _emailService.GenerateCredentialsEmailBody(
patientRegistrationDto.Email, patientRegistrationDto.Password);
await _emailService.SendEmailAsync(patientRegistrationDto.Email, "Successful registration!", body);
}
return StatusCode(response.StatusCode, response);
}