migrare UI in WebAssembly + integrare Serviciu stocare info pe web + WebToken
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
using Application.Endpoints;
|
||||
using Application.Endpoints.Doctors.Login;
|
||||
using Application.Endpoints.Authorization.Doctor;
|
||||
using Application.Endpoints.Doctors.Profile;
|
||||
using Application.Endpoints.Doctors.Registration;
|
||||
using Application.Endpoints.Doctors.ResetPassword;
|
||||
using Application.Services.Database.MongoDB;
|
||||
using Application.Services.Database.PostgreSQL;
|
||||
using Application.Services.Email;
|
||||
@@ -18,17 +17,15 @@ namespace API.Controllers;
|
||||
public class DoctorsController : ControllerBase
|
||||
{
|
||||
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
|
||||
private readonly IDoctorRepository _database;
|
||||
private readonly IDoctorRepository _doctorRepository;
|
||||
private readonly IHashingAlgorithms _hashingAlgorithms;
|
||||
private readonly IJwtService _jwtService;
|
||||
private readonly IEmailService _emailService;
|
||||
|
||||
public DoctorsController(IDoctorRepository database, IHashingAlgorithms hashingAlgorithms,
|
||||
IJwtService jwtService, IAppointmentsMongoDbService appointmentsMongoDbService, IEmailService emailService)
|
||||
public DoctorsController(IDoctorRepository doctorRepository, IHashingAlgorithms hashingAlgorithms,
|
||||
IAppointmentsMongoDbService appointmentsMongoDbService, IEmailService emailService)
|
||||
{
|
||||
_database = database;
|
||||
_doctorRepository = doctorRepository;
|
||||
_hashingAlgorithms = hashingAlgorithms;
|
||||
_jwtService = jwtService;
|
||||
_appointmentsMongoDbService = appointmentsMongoDbService;
|
||||
_emailService = emailService;
|
||||
}
|
||||
@@ -36,7 +33,7 @@ public class DoctorsController : ControllerBase
|
||||
[HttpPost("register")]
|
||||
public async Task<ActionResult<BaseResponse>> Register(DoctorRegistrationDto doctorRegistrationDto)
|
||||
{
|
||||
var handler = new DoctorRegistrationHandler(_database, _hashingAlgorithms);
|
||||
var handler = new DoctorRegistrationHandler(_doctorRepository, _hashingAlgorithms);
|
||||
var response = await handler.Handle(doctorRegistrationDto).ConfigureAwait(false);
|
||||
|
||||
if (response.StatusCode < HttpStatusCodes.BadRequest)
|
||||
@@ -49,67 +46,10 @@ public class DoctorsController : ControllerBase
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
|
||||
[HttpPost("login")]
|
||||
public async Task<ActionResult<BaseResponse>> Login(DoctorLoginDto doctorLoginDto)
|
||||
{
|
||||
var handler = new DoctorLoginHandler(_database, _hashingAlgorithms);
|
||||
var response = await handler.Handle(doctorLoginDto).ConfigureAwait(false);
|
||||
/*
|
||||
if (response.Data != null)
|
||||
{
|
||||
Doctor doctor = (Doctor)response.Data;
|
||||
var authToken = _jwtService.GenerateJwtToken(doctor.Email);
|
||||
|
||||
HttpContext.Response.Headers.Add("Authorization", $"Bearer {authToken}");
|
||||
}
|
||||
*/
|
||||
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
|
||||
[HttpPost("refresh_token")]
|
||||
public async Task<ActionResult<BaseResponse>> RefreshToken()
|
||||
{
|
||||
var authorizationHeader = Request.Headers["Authorization"].FirstOrDefault();
|
||||
if (string.IsNullOrEmpty(authorizationHeader) || !authorizationHeader.StartsWith("Bearer "))
|
||||
return StatusCode(HttpStatusCodes.BadRequest, new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.BadRequest,
|
||||
Message = "Invalid request header format.",
|
||||
Data = null
|
||||
});
|
||||
|
||||
var oldToken = authorizationHeader.Substring("Bearer ".Length).Trim();
|
||||
|
||||
if (!_jwtService.ValidateJwtToken(oldToken))
|
||||
return StatusCode(HttpStatusCodes.Unauthorized, new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.Unauthorized,
|
||||
Message = "Invalid JWT token.",
|
||||
Data = null
|
||||
});
|
||||
|
||||
var newToken = _jwtService.RefreshToken(oldToken);
|
||||
return StatusCode(HttpStatusCodes.OK, new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.OK,
|
||||
Message = "Token refreshed successfully.",
|
||||
Data = new { Token = newToken }
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost("reset_password")]
|
||||
public async Task<ActionResult<BaseResponse>> ResetPassword(DoctorResetPasswordDto resetDoctorDto)
|
||||
{
|
||||
var handler = new DoctorResetPasswordHandler(_database, _hashingAlgorithms);
|
||||
var response = await handler.Handle(resetDoctorDto).ConfigureAwait(false);
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<BaseResponse>> GetAllDoctors()
|
||||
{
|
||||
var handler = new DoctorProfileHandler(_database, _hashingAlgorithms);
|
||||
var handler = new DoctorProfileHandler(_doctorRepository, _hashingAlgorithms);
|
||||
var response = await handler.HandleGetAll();
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
@@ -117,7 +57,7 @@ public class DoctorsController : ControllerBase
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<BaseResponse>> GetDoctor(Guid id)
|
||||
{
|
||||
var handler = new DoctorProfileHandler(_database, _hashingAlgorithms);
|
||||
var handler = new DoctorProfileHandler(_doctorRepository, _hashingAlgorithms);
|
||||
var response = await handler.HandleGet(id);
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
@@ -125,7 +65,7 @@ public class DoctorsController : ControllerBase
|
||||
[HttpPut]
|
||||
public async Task<ActionResult<BaseResponse>> UpdateDoctorProfile(DoctorProfileUpdateDto doctorUpdateDto)
|
||||
{
|
||||
var handler = new DoctorProfileHandler(_database, _hashingAlgorithms);
|
||||
var handler = new DoctorProfileHandler(_doctorRepository, _hashingAlgorithms);
|
||||
var response = await handler.HandleUpdate(doctorUpdateDto).ConfigureAwait(false);
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
@@ -133,7 +73,7 @@ public class DoctorsController : ControllerBase
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<ActionResult<BaseResponse>> DeleteDoctorProfile(Guid id)
|
||||
{
|
||||
var handler = new DoctorProfileHandler(_database, _hashingAlgorithms);
|
||||
var handler = new DoctorProfileHandler(_doctorRepository, _hashingAlgorithms);
|
||||
var response = await handler.HandleDelete(id).ConfigureAwait(false);
|
||||
|
||||
if (response.StatusCode < HttpStatusCodes.BadRequest) DeleteDoctorAppointments(id);
|
||||
|
||||
Reference in New Issue
Block a user