medicalHistory: deletion when patient is deleted

This commit is contained in:
andrei-mihnea-cerbu
2024-04-08 22:06:01 +03:00
parent 13bfa2bdd9
commit 7b24c178b3
62 changed files with 321 additions and 356 deletions
+18 -30
View File
@@ -3,8 +3,8 @@ using Application.Endpoints.Doctors.Login;
using Application.Endpoints.Doctors.Profile;
using Application.Endpoints.Doctors.Registration;
using Application.Endpoints.Doctors.ResetPassword;
using Application.Services.Database;
using Application.Services.Database.MongoDB;
using Application.Services.Database.PostgreSQL;
using Application.Services.HashingAlgorithms;
using Application.Services.Jwt;
using Core.Entities;
@@ -16,10 +16,10 @@ namespace API.Controllers;
[Route("api/[controller]")]
public class DoctorsController : ControllerBase
{
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
private readonly IDoctorRepository _database;
private readonly IHashingAlgorithms _hashingAlgorithms;
private readonly IJwtService _jwtService;
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
public DoctorsController(IDoctorRepository database, IHashingAlgorithms hashingAlgorithms,
IJwtService jwtService, IAppointmentsMongoDbService appointmentsMongoDbService)
@@ -48,11 +48,11 @@ public class DoctorsController : ControllerBase
{
Doctor doctor = (Doctor)response.Data;
var authToken = _jwtService.GenerateJwtToken(doctor.Email);
HttpContext.Response.Headers.Add("Authorization", $"Bearer {authToken}");
}
*/
return StatusCode(response.StatusCode, response);
}
@@ -61,36 +61,30 @@ public class DoctorsController : ControllerBase
{
var authorizationHeader = Request.Headers["Authorization"].FirstOrDefault();
if (string.IsNullOrEmpty(authorizationHeader) || !authorizationHeader.StartsWith("Bearer "))
{
return StatusCode(HttpStatusCodes.BadRequest, new BaseResponse
{
StatusCode = HttpStatusCodes.BadRequest,
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.",
StatusCode = HttpStatusCodes.Unauthorized,
Message = "Invalid JWT token.",
Data = null
});
}
else
var newToken = _jwtService.RefreshToken(oldToken);
return StatusCode(HttpStatusCodes.OK, new BaseResponse
{
var newToken = _jwtService.RefreshToken(oldToken);
return StatusCode(HttpStatusCodes.OK, new BaseResponse
{
StatusCode = HttpStatusCodes.OK,
Message = "Token refreshed successfully.",
Data = new { Token = newToken }
});
}
StatusCode = HttpStatusCodes.OK,
Message = "Token refreshed successfully.",
Data = new { Token = newToken }
});
}
[HttpPost("reset_password")]
@@ -131,11 +125,8 @@ public class DoctorsController : ControllerBase
var handler = new DoctorProfileHandler(_database, _hashingAlgorithms);
var response = await handler.HandleDelete(id).ConfigureAwait(false);
if (response.StatusCode < HttpStatusCodes.BadRequest)
{
DeleteDoctorAppointments(id);
}
if (response.StatusCode < HttpStatusCodes.BadRequest) DeleteDoctorAppointments(id);
return StatusCode(response.StatusCode, response);
}
@@ -146,10 +137,7 @@ public class DoctorsController : ControllerBase
("DoctorId", doctorId.ToString())
};
var appointments = await _appointmentsMongoDbService.FindAsync<Appointment>(criteria);
if (!appointments.Any())
{
return;
}
if (!appointments.Any()) return;
await _appointmentsMongoDbService.DeleteByIdAsync<Appointment>(appointments[0].Id);
}
}