migrare UI in WebAssembly + integrare Serviciu stocare info pe web + WebToken
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
using Application.Endpoints;
|
||||
using Application.Endpoints.Patients.Login;
|
||||
using Application.Endpoints.Patients.Profile;
|
||||
using Application.Endpoints.Patients.Registration;
|
||||
using Application.Endpoints.Patients.ResetPassword;
|
||||
using Application.Services.Database.PostgreSQL;
|
||||
using Application.Services.HashingAlgorithms;
|
||||
using Application.Services.Email;
|
||||
@@ -17,17 +15,15 @@ namespace API.Controllers;
|
||||
public class PatientsController : ControllerBase
|
||||
{
|
||||
private readonly IHashingAlgorithms _hashingAlgorithms;
|
||||
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, IEmailService emailService)
|
||||
IMedicalHistoryRepository medicalHistory, IEmailService emailService)
|
||||
{
|
||||
_patientRepository = patientRepository;
|
||||
_hashingAlgorithms = hashingAlgorithms;
|
||||
_jwtService = jwtService;
|
||||
_medicalHistory = medicalHistory;
|
||||
_emailService = emailService;
|
||||
}
|
||||
@@ -40,65 +36,10 @@ public class PatientsController : ControllerBase
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<BaseResponse>> GetPatient(Guid id)
|
||||
{
|
||||
var handler = new PatientProfileHandler(_patientRepository, _hashingAlgorithms);
|
||||
var response = await handler.HandleGet(id);
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
|
||||
[HttpPost("login")]
|
||||
public async Task<ActionResult<BaseResponse>> Login(PatientLoginDto patientLoginDto)
|
||||
{
|
||||
var handler = new PatientLoginHandler(_patientRepository);
|
||||
var response = await handler.Handle(patientLoginDto).ConfigureAwait(false);
|
||||
/*
|
||||
if (response.Data != null)
|
||||
{
|
||||
Patient patient = (Patient)response.Data;
|
||||
var authToken = _jwtService.GenerateJwtToken(patient.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("register")]
|
||||
public async Task<ActionResult<BaseResponse>> Register(PatientRegistrationDto patientRegistrationDto)
|
||||
{
|
||||
Console.WriteLine("Esti aici");
|
||||
var handler = new PatientRegistrationHandler(_patientRepository, _hashingAlgorithms);
|
||||
var response = await handler.Handle(patientRegistrationDto).ConfigureAwait(false);
|
||||
|
||||
@@ -111,12 +52,12 @@ public class PatientsController : ControllerBase
|
||||
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
|
||||
[HttpPost("reset_password")]
|
||||
public async Task<ActionResult<BaseResponse>> ResetPassword(PatientResetPasswordDto patientResetPasswordDto)
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<BaseResponse>> GetPatient(Guid id)
|
||||
{
|
||||
var handler = new PatientResetPasswordHandler(_patientRepository, _hashingAlgorithms);
|
||||
var response = await handler.Handle(patientResetPasswordDto).ConfigureAwait(false);
|
||||
var handler = new PatientProfileHandler(_patientRepository, _hashingAlgorithms);
|
||||
var response = await handler.HandleGet(id);
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user