medicalHistory: deletion when patient is deleted
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.3" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.3"/>
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0"/>
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Application.Endpoints;
|
using Application.Endpoints;
|
||||||
using Application.Endpoints.Appointments;
|
using Application.Endpoints.Appointments;
|
||||||
using Application.Services.Database;
|
|
||||||
using Application.Services.Database.MongoDB;
|
using Application.Services.Database.MongoDB;
|
||||||
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace API.Controllers;
|
namespace API.Controllers;
|
||||||
@@ -9,8 +9,8 @@ namespace API.Controllers;
|
|||||||
public class AppointmentsController : BaseApiController
|
public class AppointmentsController : BaseApiController
|
||||||
{
|
{
|
||||||
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
|
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
|
||||||
private readonly IPatientRepository _patientRepository;
|
|
||||||
private readonly IDoctorRepository _doctorRepository;
|
private readonly IDoctorRepository _doctorRepository;
|
||||||
|
private readonly IPatientRepository _patientRepository;
|
||||||
|
|
||||||
public AppointmentsController(IAppointmentsMongoDbService appointmentsMongoDbService,
|
public AppointmentsController(IAppointmentsMongoDbService appointmentsMongoDbService,
|
||||||
IPatientRepository patientRepository, IDoctorRepository doctorRepository)
|
IPatientRepository patientRepository, IDoctorRepository doctorRepository)
|
||||||
@@ -23,7 +23,8 @@ public class AppointmentsController : BaseApiController
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<ActionResult<BaseResponse>> CreateAppointment(AppointmentManagementDto dto)
|
public async Task<ActionResult<BaseResponse>> CreateAppointment(AppointmentManagementDto dto)
|
||||||
{
|
{
|
||||||
var handler = new AppointmentManagementHandler(_appointmentsMongoDbService, _patientRepository, _doctorRepository);
|
var handler =
|
||||||
|
new AppointmentManagementHandler(_appointmentsMongoDbService, _patientRepository, _doctorRepository);
|
||||||
var response = await handler.HandleCreateAppointment(dto).ConfigureAwait(false);
|
var response = await handler.HandleCreateAppointment(dto).ConfigureAwait(false);
|
||||||
return StatusCode(response.StatusCode, response);
|
return StatusCode(response.StatusCode, response);
|
||||||
}
|
}
|
||||||
@@ -31,7 +32,8 @@ public class AppointmentsController : BaseApiController
|
|||||||
[HttpDelete]
|
[HttpDelete]
|
||||||
public async Task<ActionResult<BaseResponse>> DeleteAppointment(AppointmentManagementDto dto)
|
public async Task<ActionResult<BaseResponse>> DeleteAppointment(AppointmentManagementDto dto)
|
||||||
{
|
{
|
||||||
var handler = new AppointmentManagementHandler(_appointmentsMongoDbService, _patientRepository, _doctorRepository);
|
var handler =
|
||||||
|
new AppointmentManagementHandler(_appointmentsMongoDbService, _patientRepository, _doctorRepository);
|
||||||
var response = await handler.HandleDeleteAppointment(dto).ConfigureAwait(false);
|
var response = await handler.HandleDeleteAppointment(dto).ConfigureAwait(false);
|
||||||
return StatusCode(response.StatusCode, response);
|
return StatusCode(response.StatusCode, response);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Application.Endpoints;
|
using Application.Endpoints;
|
||||||
using Application.Endpoints.Chats;
|
using Application.Endpoints.Chats;
|
||||||
using Application.Services.Database;
|
|
||||||
using Application.Services.Database.MongoDB;
|
using Application.Services.Database.MongoDB;
|
||||||
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace API.Controllers;
|
namespace API.Controllers;
|
||||||
@@ -9,8 +9,8 @@ namespace API.Controllers;
|
|||||||
public class ChatController : BaseApiController
|
public class ChatController : BaseApiController
|
||||||
{
|
{
|
||||||
private readonly IChatMongoDbService _chatMongoDbService;
|
private readonly IChatMongoDbService _chatMongoDbService;
|
||||||
private readonly IPatientRepository _patientRepository;
|
|
||||||
private readonly IDoctorRepository _doctorRepository;
|
private readonly IDoctorRepository _doctorRepository;
|
||||||
|
private readonly IPatientRepository _patientRepository;
|
||||||
|
|
||||||
public ChatController(IChatMongoDbService chatMongoDbService, IPatientRepository patientRepository,
|
public ChatController(IChatMongoDbService chatMongoDbService, IPatientRepository patientRepository,
|
||||||
IDoctorRepository doctorRepository)
|
IDoctorRepository doctorRepository)
|
||||||
@@ -19,7 +19,7 @@ public class ChatController : BaseApiController
|
|||||||
_patientRepository = patientRepository;
|
_patientRepository = patientRepository;
|
||||||
_doctorRepository = doctorRepository;
|
_doctorRepository = doctorRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("send_message")]
|
[HttpPost("send_message")]
|
||||||
public async Task<ActionResult<BaseResponse>> SendMessage(SendMessageDto sendMessageDto)
|
public async Task<ActionResult<BaseResponse>> SendMessage(SendMessageDto sendMessageDto)
|
||||||
{
|
{
|
||||||
@@ -27,7 +27,7 @@ public class ChatController : BaseApiController
|
|||||||
var response = await handler.HandleSendMessage(sendMessageDto).ConfigureAwait(false);
|
var response = await handler.HandleSendMessage(sendMessageDto).ConfigureAwait(false);
|
||||||
return StatusCode(response.StatusCode, response);
|
return StatusCode(response.StatusCode, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("get_conversation")]
|
[HttpPost("get_conversation")]
|
||||||
public async Task<ActionResult<BaseResponse>> GetConversation(GetConversationDto getConversationDto)
|
public async Task<ActionResult<BaseResponse>> GetConversation(GetConversationDto getConversationDto)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ using Application.Endpoints.Doctors.Login;
|
|||||||
using Application.Endpoints.Doctors.Profile;
|
using Application.Endpoints.Doctors.Profile;
|
||||||
using Application.Endpoints.Doctors.Registration;
|
using Application.Endpoints.Doctors.Registration;
|
||||||
using Application.Endpoints.Doctors.ResetPassword;
|
using Application.Endpoints.Doctors.ResetPassword;
|
||||||
using Application.Services.Database;
|
|
||||||
using Application.Services.Database.MongoDB;
|
using Application.Services.Database.MongoDB;
|
||||||
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Application.Services.HashingAlgorithms;
|
using Application.Services.HashingAlgorithms;
|
||||||
using Application.Services.Jwt;
|
using Application.Services.Jwt;
|
||||||
using Core.Entities;
|
using Core.Entities;
|
||||||
@@ -16,10 +16,10 @@ namespace API.Controllers;
|
|||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
public class DoctorsController : ControllerBase
|
public class DoctorsController : ControllerBase
|
||||||
{
|
{
|
||||||
|
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
|
||||||
private readonly IDoctorRepository _database;
|
private readonly IDoctorRepository _database;
|
||||||
private readonly IHashingAlgorithms _hashingAlgorithms;
|
private readonly IHashingAlgorithms _hashingAlgorithms;
|
||||||
private readonly IJwtService _jwtService;
|
private readonly IJwtService _jwtService;
|
||||||
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
|
|
||||||
|
|
||||||
public DoctorsController(IDoctorRepository database, IHashingAlgorithms hashingAlgorithms,
|
public DoctorsController(IDoctorRepository database, IHashingAlgorithms hashingAlgorithms,
|
||||||
IJwtService jwtService, IAppointmentsMongoDbService appointmentsMongoDbService)
|
IJwtService jwtService, IAppointmentsMongoDbService appointmentsMongoDbService)
|
||||||
@@ -48,11 +48,11 @@ public class DoctorsController : ControllerBase
|
|||||||
{
|
{
|
||||||
Doctor doctor = (Doctor)response.Data;
|
Doctor doctor = (Doctor)response.Data;
|
||||||
var authToken = _jwtService.GenerateJwtToken(doctor.Email);
|
var authToken = _jwtService.GenerateJwtToken(doctor.Email);
|
||||||
|
|
||||||
HttpContext.Response.Headers.Add("Authorization", $"Bearer {authToken}");
|
HttpContext.Response.Headers.Add("Authorization", $"Bearer {authToken}");
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return StatusCode(response.StatusCode, response);
|
return StatusCode(response.StatusCode, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,36 +61,30 @@ public class DoctorsController : ControllerBase
|
|||||||
{
|
{
|
||||||
var authorizationHeader = Request.Headers["Authorization"].FirstOrDefault();
|
var authorizationHeader = Request.Headers["Authorization"].FirstOrDefault();
|
||||||
if (string.IsNullOrEmpty(authorizationHeader) || !authorizationHeader.StartsWith("Bearer "))
|
if (string.IsNullOrEmpty(authorizationHeader) || !authorizationHeader.StartsWith("Bearer "))
|
||||||
{
|
|
||||||
return StatusCode(HttpStatusCodes.BadRequest, new BaseResponse
|
return StatusCode(HttpStatusCodes.BadRequest, new BaseResponse
|
||||||
{
|
{
|
||||||
StatusCode = HttpStatusCodes.BadRequest,
|
StatusCode = HttpStatusCodes.BadRequest,
|
||||||
Message = "Invalid request header format.",
|
Message = "Invalid request header format.",
|
||||||
Data = null
|
Data = null
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
var oldToken = authorizationHeader.Substring("Bearer ".Length).Trim();
|
var oldToken = authorizationHeader.Substring("Bearer ".Length).Trim();
|
||||||
|
|
||||||
if (!_jwtService.ValidateJwtToken(oldToken))
|
if (!_jwtService.ValidateJwtToken(oldToken))
|
||||||
{
|
|
||||||
return StatusCode(HttpStatusCodes.Unauthorized, new BaseResponse
|
return StatusCode(HttpStatusCodes.Unauthorized, new BaseResponse
|
||||||
{
|
{
|
||||||
StatusCode = HttpStatusCodes.Unauthorized,
|
StatusCode = HttpStatusCodes.Unauthorized,
|
||||||
Message = "Invalid JWT token.",
|
Message = "Invalid JWT token.",
|
||||||
Data = null
|
Data = null
|
||||||
});
|
});
|
||||||
}
|
|
||||||
else
|
var newToken = _jwtService.RefreshToken(oldToken);
|
||||||
|
return StatusCode(HttpStatusCodes.OK, new BaseResponse
|
||||||
{
|
{
|
||||||
var newToken = _jwtService.RefreshToken(oldToken);
|
StatusCode = HttpStatusCodes.OK,
|
||||||
return StatusCode(HttpStatusCodes.OK, new BaseResponse
|
Message = "Token refreshed successfully.",
|
||||||
{
|
Data = new { Token = newToken }
|
||||||
StatusCode = HttpStatusCodes.OK,
|
});
|
||||||
Message = "Token refreshed successfully.",
|
|
||||||
Data = new { Token = newToken }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("reset_password")]
|
[HttpPost("reset_password")]
|
||||||
@@ -131,11 +125,8 @@ public class DoctorsController : ControllerBase
|
|||||||
var handler = new DoctorProfileHandler(_database, _hashingAlgorithms);
|
var handler = new DoctorProfileHandler(_database, _hashingAlgorithms);
|
||||||
var response = await handler.HandleDelete(id).ConfigureAwait(false);
|
var response = await handler.HandleDelete(id).ConfigureAwait(false);
|
||||||
|
|
||||||
if (response.StatusCode < HttpStatusCodes.BadRequest)
|
if (response.StatusCode < HttpStatusCodes.BadRequest) DeleteDoctorAppointments(id);
|
||||||
{
|
|
||||||
DeleteDoctorAppointments(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return StatusCode(response.StatusCode, response);
|
return StatusCode(response.StatusCode, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,10 +137,7 @@ public class DoctorsController : ControllerBase
|
|||||||
("DoctorId", doctorId.ToString())
|
("DoctorId", doctorId.ToString())
|
||||||
};
|
};
|
||||||
var appointments = await _appointmentsMongoDbService.FindAsync<Appointment>(criteria);
|
var appointments = await _appointmentsMongoDbService.FindAsync<Appointment>(criteria);
|
||||||
if (!appointments.Any())
|
if (!appointments.Any()) return;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await _appointmentsMongoDbService.DeleteByIdAsync<Appointment>(appointments[0].Id);
|
await _appointmentsMongoDbService.DeleteByIdAsync<Appointment>(appointments[0].Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using Application.Endpoints;
|
using Application.Endpoints;
|
||||||
using Application.Endpoints.MedicalHistories.FileManagement;
|
using Application.Endpoints.MedicalHistories.FileManagement;
|
||||||
using Application.Endpoints.MedicalHistories.ManageAuthorization;
|
using Application.Endpoints.MedicalHistories.ManageAuthorization;
|
||||||
using Application.Services.Database;
|
|
||||||
using Application.Services.Database.MongoDB;
|
using Application.Services.Database.MongoDB;
|
||||||
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace API.Controllers;
|
namespace API.Controllers;
|
||||||
@@ -11,10 +11,10 @@ namespace API.Controllers;
|
|||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
public class MedicalHistoryController : ControllerBase
|
public class MedicalHistoryController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
|
|
||||||
private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService;
|
|
||||||
private readonly IPatientRepository _patientRepository;
|
|
||||||
private readonly IDoctorRepository _doctorRepository;
|
private readonly IDoctorRepository _doctorRepository;
|
||||||
|
private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService;
|
||||||
|
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
|
||||||
|
private readonly IPatientRepository _patientRepository;
|
||||||
|
|
||||||
public MedicalHistoryController(IMedicalHistoryRepository medicalHistoryRepository,
|
public MedicalHistoryController(IMedicalHistoryRepository medicalHistoryRepository,
|
||||||
IPatientRepository patientRepository, IMedicalHistoryMongoDbService mongoDbService,
|
IPatientRepository patientRepository, IMedicalHistoryMongoDbService mongoDbService,
|
||||||
@@ -81,7 +81,7 @@ public class MedicalHistoryController : ControllerBase
|
|||||||
var response = await handler.HandleGrantDoctorAccess(infoDto);
|
var response = await handler.HandleGrantDoctorAccess(infoDto);
|
||||||
return StatusCode(response.StatusCode, response);
|
return StatusCode(response.StatusCode, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut("revoke_access")]
|
[HttpPut("revoke_access")]
|
||||||
public async Task<ActionResult<BaseResponse>> RevokeAccessToMedicalHistory(
|
public async Task<ActionResult<BaseResponse>> RevokeAccessToMedicalHistory(
|
||||||
MedicalHistoryManageAuthorizationDoctorDto infoDto)
|
MedicalHistoryManageAuthorizationDoctorDto infoDto)
|
||||||
|
|||||||
@@ -3,10 +3,9 @@ using Application.Endpoints.Patients.Login;
|
|||||||
using Application.Endpoints.Patients.Profile;
|
using Application.Endpoints.Patients.Profile;
|
||||||
using Application.Endpoints.Patients.Registration;
|
using Application.Endpoints.Patients.Registration;
|
||||||
using Application.Endpoints.Patients.ResetPassword;
|
using Application.Endpoints.Patients.ResetPassword;
|
||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Application.Services.HashingAlgorithms;
|
using Application.Services.HashingAlgorithms;
|
||||||
using Application.Services.Jwt;
|
using Application.Services.Jwt;
|
||||||
using Core.Entities;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace API.Controllers;
|
namespace API.Controllers;
|
||||||
@@ -16,15 +15,17 @@ namespace API.Controllers;
|
|||||||
public class PatientsController : ControllerBase
|
public class PatientsController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly IHashingAlgorithms _hashingAlgorithms;
|
private readonly IHashingAlgorithms _hashingAlgorithms;
|
||||||
private readonly IPatientRepository _patientRepository;
|
|
||||||
private readonly IJwtService _jwtService;
|
private readonly IJwtService _jwtService;
|
||||||
|
private readonly IMedicalHistoryRepository _medicalHistory;
|
||||||
|
private readonly IPatientRepository _patientRepository;
|
||||||
|
|
||||||
public PatientsController(IPatientRepository patientRepository, IHashingAlgorithms hashingAlgorithms,
|
public PatientsController(IPatientRepository patientRepository, IHashingAlgorithms hashingAlgorithms,
|
||||||
IJwtService jwtService)
|
IJwtService jwtService, IMedicalHistoryRepository medicalHistory)
|
||||||
{
|
{
|
||||||
_patientRepository = patientRepository;
|
_patientRepository = patientRepository;
|
||||||
_hashingAlgorithms = hashingAlgorithms;
|
_hashingAlgorithms = hashingAlgorithms;
|
||||||
_jwtService = jwtService;
|
_jwtService = jwtService;
|
||||||
|
_medicalHistory = medicalHistory;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@@ -53,48 +54,42 @@ public class PatientsController : ControllerBase
|
|||||||
{
|
{
|
||||||
Patient patient = (Patient)response.Data;
|
Patient patient = (Patient)response.Data;
|
||||||
var authToken = _jwtService.GenerateJwtToken(patient.Email);
|
var authToken = _jwtService.GenerateJwtToken(patient.Email);
|
||||||
|
|
||||||
HttpContext.Response.Headers.Add("Authorization", $"Bearer {authToken}");
|
HttpContext.Response.Headers.Add("Authorization", $"Bearer {authToken}");
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
return StatusCode(response.StatusCode, response);
|
return StatusCode(response.StatusCode, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("refresh_token")]
|
[HttpPost("refresh_token")]
|
||||||
public async Task<ActionResult<BaseResponse>> RefreshToken()
|
public async Task<ActionResult<BaseResponse>> RefreshToken()
|
||||||
{
|
{
|
||||||
var authorizationHeader = Request.Headers["Authorization"].FirstOrDefault();
|
var authorizationHeader = Request.Headers["Authorization"].FirstOrDefault();
|
||||||
if (string.IsNullOrEmpty(authorizationHeader) || !authorizationHeader.StartsWith("Bearer "))
|
if (string.IsNullOrEmpty(authorizationHeader) || !authorizationHeader.StartsWith("Bearer "))
|
||||||
{
|
|
||||||
return StatusCode(HttpStatusCodes.BadRequest, new BaseResponse
|
return StatusCode(HttpStatusCodes.BadRequest, new BaseResponse
|
||||||
{
|
{
|
||||||
StatusCode = HttpStatusCodes.BadRequest,
|
StatusCode = HttpStatusCodes.BadRequest,
|
||||||
Message = "Invalid request header format.",
|
Message = "Invalid request header format.",
|
||||||
Data = null
|
Data = null
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
var oldToken = authorizationHeader.Substring("Bearer ".Length).Trim();
|
var oldToken = authorizationHeader.Substring("Bearer ".Length).Trim();
|
||||||
|
|
||||||
if (!_jwtService.ValidateJwtToken(oldToken))
|
if (!_jwtService.ValidateJwtToken(oldToken))
|
||||||
{
|
|
||||||
return StatusCode(HttpStatusCodes.Unauthorized, new BaseResponse
|
return StatusCode(HttpStatusCodes.Unauthorized, new BaseResponse
|
||||||
{
|
{
|
||||||
StatusCode = HttpStatusCodes.Unauthorized,
|
StatusCode = HttpStatusCodes.Unauthorized,
|
||||||
Message = "Invalid JWT token.",
|
Message = "Invalid JWT token.",
|
||||||
Data = null
|
Data = null
|
||||||
});
|
});
|
||||||
}
|
|
||||||
else
|
var newToken = _jwtService.RefreshToken(oldToken);
|
||||||
|
return StatusCode(HttpStatusCodes.OK, new BaseResponse
|
||||||
{
|
{
|
||||||
var newToken = _jwtService.RefreshToken(oldToken);
|
StatusCode = HttpStatusCodes.OK,
|
||||||
return StatusCode(HttpStatusCodes.OK, new BaseResponse
|
Message = "Token refreshed successfully.",
|
||||||
{
|
Data = new { Token = newToken }
|
||||||
StatusCode = HttpStatusCodes.OK,
|
});
|
||||||
Message = "Token refreshed successfully.",
|
|
||||||
Data = new { Token = newToken }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("register")]
|
[HttpPost("register")]
|
||||||
@@ -126,6 +121,20 @@ public class PatientsController : ControllerBase
|
|||||||
{
|
{
|
||||||
var handler = new PatientProfileHandler(_patientRepository, _hashingAlgorithms);
|
var handler = new PatientProfileHandler(_patientRepository, _hashingAlgorithms);
|
||||||
var response = await handler.HandleDelete(id).ConfigureAwait(false);
|
var response = await handler.HandleDelete(id).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (response.StatusCode < HttpStatusCodes.BadRequest) DeleteMedicalHistory(id);
|
||||||
|
|
||||||
return StatusCode(response.StatusCode, response);
|
return StatusCode(response.StatusCode, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void DeleteMedicalHistory(Guid patientId)
|
||||||
|
{
|
||||||
|
var medicalHistoryList = await _medicalHistory.GetAllAsync();
|
||||||
|
foreach (var med in medicalHistoryList)
|
||||||
|
if (med.UserId == patientId)
|
||||||
|
{
|
||||||
|
await _medicalHistory.DeleteAsync(med);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,15 +2,11 @@
|
|||||||
|
|
||||||
namespace API.Middlewares;
|
namespace API.Middlewares;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
public class ApiKeyMiddleware
|
public class ApiKeyMiddleware
|
||||||
{
|
{
|
||||||
private readonly RequestDelegate _next;
|
|
||||||
private const string API_KEY_HEADER_NAME = "ApiKey";
|
private const string API_KEY_HEADER_NAME = "ApiKey";
|
||||||
private readonly string _apiKey;
|
private readonly string _apiKey;
|
||||||
|
private readonly RequestDelegate _next;
|
||||||
|
|
||||||
public ApiKeyMiddleware(RequestDelegate next, IConfiguration configuration)
|
public ApiKeyMiddleware(RequestDelegate next, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,18 +1,14 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Application.Endpoints;
|
using Application.Endpoints;
|
||||||
|
using Application.Services.Jwt;
|
||||||
|
|
||||||
namespace API.Middlewares;
|
namespace API.Middlewares;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Linq;
|
|
||||||
using Application.Services.Jwt;
|
|
||||||
|
|
||||||
public class JwtMiddleware
|
public class JwtMiddleware
|
||||||
{
|
{
|
||||||
private readonly RequestDelegate _next;
|
|
||||||
private readonly IJwtService _jwtService;
|
private readonly IJwtService _jwtService;
|
||||||
|
private readonly RequestDelegate _next;
|
||||||
|
|
||||||
public JwtMiddleware(RequestDelegate next, IJwtService jwtService)
|
public JwtMiddleware(RequestDelegate next, IJwtService jwtService)
|
||||||
{
|
{
|
||||||
_next = next;
|
_next = next;
|
||||||
@@ -24,7 +20,7 @@ public class JwtMiddleware
|
|||||||
var path = context.Request.Path.ToString().ToLower();
|
var path = context.Request.Path.ToString().ToLower();
|
||||||
|
|
||||||
// Define the paths that should bypass JWT validation
|
// Define the paths that should bypass JWT validation
|
||||||
var bypassPaths = new string[]
|
var bypassPaths = new[]
|
||||||
{
|
{
|
||||||
"/api/doctors/login",
|
"/api/doctors/login",
|
||||||
"/api/doctors/register",
|
"/api/doctors/register",
|
||||||
|
|||||||
@@ -1,15 +1,9 @@
|
|||||||
using System.Text;
|
|
||||||
using API.Middlewares;
|
using API.Middlewares;
|
||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using Infrastructure.Data;
|
using Infrastructure.Data;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
||||||
using Microsoft.IdentityModel.Tokens;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("API")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("API")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8663a186a056b0dfbfeebf9ae16be42b40101093")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+13bfa2bdd901a8b258d4cf881b5bb079066ab1c6")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("API")]
|
[assembly: System.Reflection.AssemblyProductAttribute("API")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("API")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("API")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
a61f57beead854c5be97ca0cf9336ea23b19a3b596fd07a95a410574950b1887
|
8e0774eef99f1b59f0ed0c9c924ec32f6e145f2aa7df39a7b5a2d83ccc6da96b
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.MongoDB;
|
||||||
using Application.Services.Database.MongoDB;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Core.Entities;
|
using Core.Entities;
|
||||||
|
|
||||||
namespace Application.Endpoints.Appointments;
|
namespace Application.Endpoints.Appointments;
|
||||||
@@ -7,8 +7,8 @@ namespace Application.Endpoints.Appointments;
|
|||||||
public class AppointmentManagementHandler
|
public class AppointmentManagementHandler
|
||||||
{
|
{
|
||||||
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
|
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
|
||||||
private readonly IPatientRepository _patientRepository;
|
|
||||||
private readonly IDoctorRepository _doctorRepository;
|
private readonly IDoctorRepository _doctorRepository;
|
||||||
|
private readonly IPatientRepository _patientRepository;
|
||||||
|
|
||||||
public AppointmentManagementHandler(IAppointmentsMongoDbService appointmentsMongoDbService,
|
public AppointmentManagementHandler(IAppointmentsMongoDbService appointmentsMongoDbService,
|
||||||
IPatientRepository patientRepository, IDoctorRepository doctorRepository)
|
IPatientRepository patientRepository, IDoctorRepository doctorRepository)
|
||||||
@@ -41,18 +41,18 @@ public class AppointmentManagementHandler
|
|||||||
var appointmentId = IdentifierGenerator.GenerateId(dto.DoctorId, dto.PatientId);
|
var appointmentId = IdentifierGenerator.GenerateId(dto.DoctorId, dto.PatientId);
|
||||||
var criteria = new List<(string FieldName, string Value)>
|
var criteria = new List<(string FieldName, string Value)>
|
||||||
{
|
{
|
||||||
("_id", appointmentId),
|
("_id", appointmentId)
|
||||||
};
|
};
|
||||||
var appointments = await _appointmentsMongoDbService.FindAsync<Appointment>(criteria);
|
var appointments = await _appointmentsMongoDbService.FindAsync<Appointment>(criteria);
|
||||||
|
|
||||||
if(!appointments.Any())
|
if (!appointments.Any())
|
||||||
{
|
{
|
||||||
var appointment = new Appointment();
|
var appointment = new Appointment();
|
||||||
appointment.SetId(appointmentId);
|
appointment.SetId(appointmentId);
|
||||||
appointment.SetDoctorIid(dto.DoctorId.ToString());
|
appointment.SetDoctorIid(dto.DoctorId.ToString());
|
||||||
appointment.SetPatientId(dto.PatientId.ToString());
|
appointment.SetPatientId(dto.PatientId.ToString());
|
||||||
appointment.AddAppointment(dto.Appointment);
|
appointment.AddAppointment(dto.Appointment);
|
||||||
|
|
||||||
await _appointmentsMongoDbService.AddAsync(appointment);
|
await _appointmentsMongoDbService.AddAsync(appointment);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -62,14 +62,14 @@ public class AppointmentManagementHandler
|
|||||||
await _appointmentsMongoDbService.ModifyAsync("_id", appointmentId, appointment);
|
await _appointmentsMongoDbService.ModifyAsync("_id", appointmentId, appointment);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new BaseResponse()
|
return new BaseResponse
|
||||||
{
|
{
|
||||||
StatusCode = HttpStatusCodes.Created,
|
StatusCode = HttpStatusCodes.Created,
|
||||||
Message = "Appointment successfully created.",
|
Message = "Appointment successfully created.",
|
||||||
Data = null
|
Data = null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<BaseResponse> HandleDeleteAppointment(AppointmentManagementDto dto)
|
public async Task<BaseResponse> HandleDeleteAppointment(AppointmentManagementDto dto)
|
||||||
{
|
{
|
||||||
var validation = new DeleteAppointmentValidator(_appointmentsMongoDbService,
|
var validation = new DeleteAppointmentValidator(_appointmentsMongoDbService,
|
||||||
@@ -89,29 +89,27 @@ public class AppointmentManagementHandler
|
|||||||
Data = null
|
Data = null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var appointmentId = IdentifierGenerator.GenerateId(dto.DoctorId, dto.PatientId);
|
var appointmentId = IdentifierGenerator.GenerateId(dto.DoctorId, dto.PatientId);
|
||||||
var criteria = new List<(string FieldName, string Value)>
|
var criteria = new List<(string FieldName, string Value)>
|
||||||
{
|
{
|
||||||
("_id", appointmentId),
|
("_id", appointmentId)
|
||||||
};
|
};
|
||||||
var appointments = await _appointmentsMongoDbService.FindAsync<Appointment>(criteria);
|
var appointments = await _appointmentsMongoDbService.FindAsync<Appointment>(criteria);
|
||||||
|
|
||||||
if(!appointments.Any())
|
if (!appointments.Any())
|
||||||
{
|
return new BaseResponse
|
||||||
return new BaseResponse()
|
|
||||||
{
|
{
|
||||||
StatusCode = HttpStatusCodes.NotFound,
|
StatusCode = HttpStatusCodes.NotFound,
|
||||||
Message = "Appointment not found in system.",
|
Message = "Appointment not found in system.",
|
||||||
Data = null
|
Data = null
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
var appointment = appointments[0];
|
var appointment = appointments[0];
|
||||||
appointment.RemoveAppointment(dto.Appointment);
|
appointment.RemoveAppointment(dto.Appointment);
|
||||||
await _appointmentsMongoDbService.ModifyAsync("_id", appointmentId, appointment);
|
await _appointmentsMongoDbService.ModifyAsync("_id", appointmentId, appointment);
|
||||||
|
|
||||||
return new BaseResponse()
|
return new BaseResponse
|
||||||
{
|
{
|
||||||
StatusCode = HttpStatusCodes.OK,
|
StatusCode = HttpStatusCodes.OK,
|
||||||
Message = "Appointment successfully removed.",
|
Message = "Appointment successfully removed.",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.MongoDB;
|
||||||
using Application.Services.Database.MongoDB;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|
||||||
namespace Application.Endpoints.Appointments;
|
namespace Application.Endpoints.Appointments;
|
||||||
@@ -9,7 +9,7 @@ public class CreateAppointmentValidator : AbstractValidator<AppointmentManagemen
|
|||||||
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
|
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
|
||||||
private readonly IDoctorRepository _doctorRepository;
|
private readonly IDoctorRepository _doctorRepository;
|
||||||
private readonly IPatientRepository _patientRepository;
|
private readonly IPatientRepository _patientRepository;
|
||||||
|
|
||||||
public CreateAppointmentValidator(IAppointmentsMongoDbService appointmentsMongoDbService,
|
public CreateAppointmentValidator(IAppointmentsMongoDbService appointmentsMongoDbService,
|
||||||
IDoctorRepository doctorRepository, IPatientRepository patientRepository)
|
IDoctorRepository doctorRepository, IPatientRepository patientRepository)
|
||||||
{
|
{
|
||||||
@@ -17,7 +17,7 @@ public class CreateAppointmentValidator : AbstractValidator<AppointmentManagemen
|
|||||||
.NotEmpty().WithMessage("Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
|
.NotEmpty().WithMessage("Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
|
||||||
.MustAsync(IsDoctorRegistered).WithMessage("Doctor is not registered in system")
|
.MustAsync(IsDoctorRegistered).WithMessage("Doctor is not registered in system")
|
||||||
.WithErrorCode(HttpStatusCodes.NotFound.ToString());
|
.WithErrorCode(HttpStatusCodes.NotFound.ToString());
|
||||||
|
|
||||||
RuleFor(x => x.PatientId)
|
RuleFor(x => x.PatientId)
|
||||||
.NotEmpty().WithMessage("Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
|
.NotEmpty().WithMessage("Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
|
||||||
.MustAsync(IsPatientRegistered).WithMessage("Patient is not registered in system")
|
.MustAsync(IsPatientRegistered).WithMessage("Patient is not registered in system")
|
||||||
@@ -30,18 +30,18 @@ public class CreateAppointmentValidator : AbstractValidator<AppointmentManagemen
|
|||||||
RuleFor(x => x)
|
RuleFor(x => x)
|
||||||
.MustAsync(IsAppointmentUnique).WithMessage("Appointment already in system.")
|
.MustAsync(IsAppointmentUnique).WithMessage("Appointment already in system.")
|
||||||
.WithErrorCode(HttpStatusCodes.Conflict.ToString());
|
.WithErrorCode(HttpStatusCodes.Conflict.ToString());
|
||||||
|
|
||||||
_appointmentsMongoDbService = appointmentsMongoDbService;
|
_appointmentsMongoDbService = appointmentsMongoDbService;
|
||||||
_doctorRepository = doctorRepository;
|
_doctorRepository = doctorRepository;
|
||||||
_patientRepository = patientRepository;
|
_patientRepository = patientRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> IsDoctorRegistered(Guid id, CancellationToken cancellationToken)
|
private async Task<bool> IsDoctorRegistered(Guid id, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var doctor = await _doctorRepository.GetByIdAsync(id);
|
var doctor = await _doctorRepository.GetByIdAsync(id);
|
||||||
return doctor != null;
|
return doctor != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> IsPatientRegistered(Guid id, CancellationToken cancellationToken)
|
private async Task<bool> IsPatientRegistered(Guid id, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var patient = await _patientRepository.GetByIdAsync(id);
|
var patient = await _patientRepository.GetByIdAsync(id);
|
||||||
@@ -50,9 +50,9 @@ public class CreateAppointmentValidator : AbstractValidator<AppointmentManagemen
|
|||||||
|
|
||||||
private bool IsAppointmentValidFormat(DateTime appointment)
|
private bool IsAppointmentValidFormat(DateTime appointment)
|
||||||
{
|
{
|
||||||
if (appointment == default(DateTime))
|
if (appointment == default)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (appointment.Date < DateTime.UtcNow.Date)
|
if (appointment.Date < DateTime.UtcNow.Date)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.MongoDB;
|
||||||
using Application.Services.Database.MongoDB;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Core.Entities;
|
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|
||||||
namespace Application.Endpoints.Appointments;
|
namespace Application.Endpoints.Appointments;
|
||||||
@@ -10,7 +9,7 @@ public class DeleteAppointmentValidator : AbstractValidator<AppointmentManagemen
|
|||||||
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
|
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
|
||||||
private readonly IDoctorRepository _doctorRepository;
|
private readonly IDoctorRepository _doctorRepository;
|
||||||
private readonly IPatientRepository _patientRepository;
|
private readonly IPatientRepository _patientRepository;
|
||||||
|
|
||||||
public DeleteAppointmentValidator(IAppointmentsMongoDbService appointmentsMongoDbService,
|
public DeleteAppointmentValidator(IAppointmentsMongoDbService appointmentsMongoDbService,
|
||||||
IDoctorRepository doctorRepository, IPatientRepository patientRepository)
|
IDoctorRepository doctorRepository, IPatientRepository patientRepository)
|
||||||
{
|
{
|
||||||
@@ -18,7 +17,7 @@ public class DeleteAppointmentValidator : AbstractValidator<AppointmentManagemen
|
|||||||
.NotEmpty().WithMessage("Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
|
.NotEmpty().WithMessage("Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
|
||||||
.MustAsync(IsDoctorRegistered).WithMessage("Doctor is not registered in system")
|
.MustAsync(IsDoctorRegistered).WithMessage("Doctor is not registered in system")
|
||||||
.WithErrorCode(HttpStatusCodes.NotFound.ToString());
|
.WithErrorCode(HttpStatusCodes.NotFound.ToString());
|
||||||
|
|
||||||
RuleFor(x => x.PatientId)
|
RuleFor(x => x.PatientId)
|
||||||
.NotEmpty().WithMessage("Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
|
.NotEmpty().WithMessage("Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
|
||||||
.MustAsync(IsPatientRegistered).WithMessage("Patient is not registered in system")
|
.MustAsync(IsPatientRegistered).WithMessage("Patient is not registered in system")
|
||||||
@@ -31,18 +30,18 @@ public class DeleteAppointmentValidator : AbstractValidator<AppointmentManagemen
|
|||||||
RuleFor(x => x)
|
RuleFor(x => x)
|
||||||
.MustAsync(DoesAppointmentExists).WithMessage("Appointment not found in system")
|
.MustAsync(DoesAppointmentExists).WithMessage("Appointment not found in system")
|
||||||
.WithErrorCode(HttpStatusCodes.NotFound.ToString());
|
.WithErrorCode(HttpStatusCodes.NotFound.ToString());
|
||||||
|
|
||||||
_appointmentsMongoDbService = appointmentsMongoDbService;
|
_appointmentsMongoDbService = appointmentsMongoDbService;
|
||||||
_doctorRepository = doctorRepository;
|
_doctorRepository = doctorRepository;
|
||||||
_patientRepository = patientRepository;
|
_patientRepository = patientRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> IsDoctorRegistered(Guid id, CancellationToken cancellationToken)
|
private async Task<bool> IsDoctorRegistered(Guid id, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var doctor = await _doctorRepository.GetByIdAsync(id);
|
var doctor = await _doctorRepository.GetByIdAsync(id);
|
||||||
return doctor != null;
|
return doctor != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> IsPatientRegistered(Guid id, CancellationToken cancellationToken)
|
private async Task<bool> IsPatientRegistered(Guid id, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var patient = await _patientRepository.GetByIdAsync(id);
|
var patient = await _patientRepository.GetByIdAsync(id);
|
||||||
@@ -51,9 +50,9 @@ public class DeleteAppointmentValidator : AbstractValidator<AppointmentManagemen
|
|||||||
|
|
||||||
private bool IsAppointmentValidFormat(DateTime appointment)
|
private bool IsAppointmentValidFormat(DateTime appointment)
|
||||||
{
|
{
|
||||||
if (appointment == default(DateTime))
|
if (appointment == default)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (appointment.Date < DateTime.UtcNow.Date)
|
if (appointment.Date < DateTime.UtcNow.Date)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.MongoDB;
|
||||||
using Application.Services.Database.MongoDB;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Core.Entities;
|
using Core.Entities;
|
||||||
|
|
||||||
namespace Application.Endpoints.Chats;
|
namespace Application.Endpoints.Chats;
|
||||||
@@ -7,8 +7,8 @@ namespace Application.Endpoints.Chats;
|
|||||||
public class ChatHandler
|
public class ChatHandler
|
||||||
{
|
{
|
||||||
private readonly IChatMongoDbService _chatMongoDbService;
|
private readonly IChatMongoDbService _chatMongoDbService;
|
||||||
private readonly IPatientRepository _patientRepository;
|
|
||||||
private readonly IDoctorRepository _doctorRepository;
|
private readonly IDoctorRepository _doctorRepository;
|
||||||
|
private readonly IPatientRepository _patientRepository;
|
||||||
|
|
||||||
public ChatHandler(IChatMongoDbService chatMongoDbService, IPatientRepository patientRepository,
|
public ChatHandler(IChatMongoDbService chatMongoDbService, IPatientRepository patientRepository,
|
||||||
IDoctorRepository doctorRepository)
|
IDoctorRepository doctorRepository)
|
||||||
@@ -38,30 +38,26 @@ public class ChatHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!await CheckForUsersExistence(sendMessageDto.Sender, sendMessageDto.Receiver))
|
if (!await CheckForUsersExistence(sendMessageDto.Sender, sendMessageDto.Receiver))
|
||||||
{
|
|
||||||
return new BaseResponse
|
return new BaseResponse
|
||||||
{
|
{
|
||||||
StatusCode = HttpStatusCodes.BadRequest,
|
StatusCode = HttpStatusCodes.BadRequest,
|
||||||
Message = "Users can't be found in the system.",
|
Message = "Users can't be found in the system.",
|
||||||
Data = null
|
Data = null
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
var chatId = IdentifierGenerator.GenerateId(sendMessageDto.Sender, sendMessageDto.Receiver);
|
var chatId = IdentifierGenerator.GenerateId(sendMessageDto.Sender, sendMessageDto.Receiver);
|
||||||
|
|
||||||
var criteria = new List<(string, string)>();
|
var criteria = new List<(string, string)>();
|
||||||
criteria.Add(("_id", chatId));
|
criteria.Add(("_id", chatId));
|
||||||
|
|
||||||
var documents = await _chatMongoDbService.FindAsync<Chat>(criteria);
|
var documents = await _chatMongoDbService.FindAsync<Chat>(criteria);
|
||||||
if (!documents.Any())
|
if (!documents.Any())
|
||||||
{
|
return new BaseResponse
|
||||||
return new BaseResponse()
|
|
||||||
{
|
{
|
||||||
StatusCode = HttpStatusCodes.NotFound,
|
StatusCode = HttpStatusCodes.NotFound,
|
||||||
Message = "Access to medical history not found.",
|
Message = "Access to medical history not found.",
|
||||||
Data = null
|
Data = null
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
var chat = documents[0].Messages;
|
var chat = documents[0].Messages;
|
||||||
chat.Add(new Message(sendMessageDto.Sender, sendMessageDto.Message));
|
chat.Add(new Message(sendMessageDto.Sender, sendMessageDto.Message));
|
||||||
@@ -71,7 +67,7 @@ public class ChatHandler
|
|||||||
newChat.SetMessages(chat);
|
newChat.SetMessages(chat);
|
||||||
|
|
||||||
await _chatMongoDbService.ModifyAsync("_id", chatId, newChat);
|
await _chatMongoDbService.ModifyAsync("_id", chatId, newChat);
|
||||||
|
|
||||||
return new BaseResponse
|
return new BaseResponse
|
||||||
{
|
{
|
||||||
StatusCode = HttpStatusCodes.NoContent,
|
StatusCode = HttpStatusCodes.NoContent,
|
||||||
@@ -100,20 +96,18 @@ public class ChatHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!await CheckForUsersExistence(getConversationDto.IdUser1, getConversationDto.IdUser2))
|
if (!await CheckForUsersExistence(getConversationDto.IdUser1, getConversationDto.IdUser2))
|
||||||
{
|
|
||||||
return new BaseResponse
|
return new BaseResponse
|
||||||
{
|
{
|
||||||
StatusCode = HttpStatusCodes.BadRequest,
|
StatusCode = HttpStatusCodes.BadRequest,
|
||||||
Message = "Users can't be found in the system.",
|
Message = "Users can't be found in the system.",
|
||||||
Data = null
|
Data = null
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
var chatId = IdentifierGenerator.GenerateId(getConversationDto.IdUser1, getConversationDto.IdUser2);
|
var chatId = IdentifierGenerator.GenerateId(getConversationDto.IdUser1, getConversationDto.IdUser2);
|
||||||
|
|
||||||
var criteria = new List<(string, string)>();
|
var criteria = new List<(string, string)>();
|
||||||
criteria.Add(("_id", chatId));
|
criteria.Add(("_id", chatId));
|
||||||
|
|
||||||
Chat? chat = null;
|
Chat? chat = null;
|
||||||
|
|
||||||
var documents = await _chatMongoDbService.FindAsync<Chat>(criteria);
|
var documents = await _chatMongoDbService.FindAsync<Chat>(criteria);
|
||||||
@@ -128,7 +122,7 @@ public class ChatHandler
|
|||||||
{
|
{
|
||||||
chat = documents[0];
|
chat = documents[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
return new BaseResponse
|
return new BaseResponse
|
||||||
{
|
{
|
||||||
StatusCode = HttpStatusCodes.OK,
|
StatusCode = HttpStatusCodes.OK,
|
||||||
@@ -141,7 +135,7 @@ public class ChatHandler
|
|||||||
{
|
{
|
||||||
var firstCheck = await _patientRepository.GetByIdAsync(idUser1) != null &&
|
var firstCheck = await _patientRepository.GetByIdAsync(idUser1) != null &&
|
||||||
await _doctorRepository.GetByIdAsync(idUser2) != null;
|
await _doctorRepository.GetByIdAsync(idUser2) != null;
|
||||||
|
|
||||||
var secondCheck = await _patientRepository.GetByIdAsync(idUser2) != null &&
|
var secondCheck = await _patientRepository.GetByIdAsync(idUser2) != null &&
|
||||||
await _doctorRepository.GetByIdAsync(idUser1) != null;
|
await _doctorRepository.GetByIdAsync(idUser1) != null;
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class SendMessageValidator : AbstractValidator<SendMessageDto>
|
|||||||
|
|
||||||
RuleFor(x => x.Receiver)
|
RuleFor(x => x.Receiver)
|
||||||
.NotEmpty().WithMessage("Receiver Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString());
|
.NotEmpty().WithMessage("Receiver Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString());
|
||||||
|
|
||||||
RuleFor(x => x.Message)
|
RuleFor(x => x.Message)
|
||||||
.NotEmpty().WithMessage("Message is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString());
|
.NotEmpty().WithMessage("Message is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Application.Services.HashingAlgorithms;
|
using Application.Services.HashingAlgorithms;
|
||||||
|
|
||||||
namespace Application.Endpoints.Doctors.Login;
|
namespace Application.Endpoints.Doctors.Login;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|
||||||
namespace Application.Endpoints.Doctors.Login;
|
namespace Application.Endpoints.Doctors.Login;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Application.Services.HashingAlgorithms;
|
using Application.Services.HashingAlgorithms;
|
||||||
|
|
||||||
namespace Application.Endpoints.Doctors.Profile;
|
namespace Application.Endpoints.Doctors.Profile;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|
||||||
namespace Application.Endpoints.Doctors.Profile;
|
namespace Application.Endpoints.Doctors.Profile;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Application.Services.HashingAlgorithms;
|
using Application.Services.HashingAlgorithms;
|
||||||
using Core.Entities;
|
using Core.Entities;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|
||||||
namespace Application.Endpoints.Doctors.Registration;
|
namespace Application.Endpoints.Doctors.Registration;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Application.Services.HashingAlgorithms;
|
using Application.Services.HashingAlgorithms;
|
||||||
|
|
||||||
namespace Application.Endpoints.Doctors.ResetPassword;
|
namespace Application.Endpoints.Doctors.ResetPassword;
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|
||||||
namespace Application.Endpoints.Doctors.ResetPassword;
|
namespace Application.Endpoints.Doctors.ResetPassword;
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ public class IdentifierGenerator
|
|||||||
public static string GenerateId(Guid id1, Guid id2)
|
public static string GenerateId(Guid id1, Guid id2)
|
||||||
{
|
{
|
||||||
// Convert GUIDs to strings
|
// Convert GUIDs to strings
|
||||||
string strId1 = id1.ToString();
|
var strId1 = id1.ToString();
|
||||||
string strId2 = id2.ToString();
|
var strId2 = id2.ToString();
|
||||||
|
|
||||||
// Sort the GUID strings
|
// Sort the GUID strings
|
||||||
string firstId = strId1.CompareTo(strId2) < 0 ? strId1 : strId2;
|
var firstId = strId1.CompareTo(strId2) < 0 ? strId1 : strId2;
|
||||||
string secondId = strId1.CompareTo(strId2) < 0 ? strId2 : strId1;
|
var secondId = strId1.CompareTo(strId2) < 0 ? strId2 : strId1;
|
||||||
|
|
||||||
// Combine them to get a symmetric string
|
// Combine them to get a symmetric string
|
||||||
return firstId + "-" + secondId;
|
return firstId + "-" + secondId;
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|
||||||
namespace Application.Endpoints.MedicalHistories.FileManagement;
|
namespace Application.Endpoints.MedicalHistories.FileManagement;
|
||||||
|
|||||||
+3
-3
@@ -1,13 +1,13 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.MongoDB;
|
||||||
using Application.Services.Database.MongoDB;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Core.Entities;
|
using Core.Entities;
|
||||||
|
|
||||||
namespace Application.Endpoints.MedicalHistories.FileManagement;
|
namespace Application.Endpoints.MedicalHistories.FileManagement;
|
||||||
|
|
||||||
public class MedicalHistoryFileManagementHandler
|
public class MedicalHistoryFileManagementHandler
|
||||||
{
|
{
|
||||||
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
|
|
||||||
private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService;
|
private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService;
|
||||||
|
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
|
||||||
private readonly IPatientRepository _patientRepository;
|
private readonly IPatientRepository _patientRepository;
|
||||||
|
|
||||||
public MedicalHistoryFileManagementHandler(IMedicalHistoryRepository medicalHistoryRepository,
|
public MedicalHistoryFileManagementHandler(IMedicalHistoryRepository medicalHistoryRepository,
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|
||||||
namespace Application.Endpoints.MedicalHistories.FileManagement;
|
namespace Application.Endpoints.MedicalHistories.FileManagement;
|
||||||
|
|||||||
+15
-23
@@ -1,13 +1,13 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.MongoDB;
|
||||||
using Application.Services.Database.MongoDB;
|
using Application.Services.Database.PostgreSQL;
|
||||||
|
|
||||||
namespace Application.Endpoints.MedicalHistories.ManageAuthorization;
|
namespace Application.Endpoints.MedicalHistories.ManageAuthorization;
|
||||||
|
|
||||||
public class MedicalHistoryManageAuthorizationHandler
|
public class MedicalHistoryManageAuthorizationHandler
|
||||||
{
|
{
|
||||||
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
|
|
||||||
private readonly IDoctorRepository _doctorRepository;
|
private readonly IDoctorRepository _doctorRepository;
|
||||||
private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService;
|
private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService;
|
||||||
|
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
|
||||||
|
|
||||||
public MedicalHistoryManageAuthorizationHandler(IMedicalHistoryRepository medicalHistoryRepository,
|
public MedicalHistoryManageAuthorizationHandler(IMedicalHistoryRepository medicalHistoryRepository,
|
||||||
IMedicalHistoryMongoDbService medicalHistoryMongoDbService, IDoctorRepository doctorRepository)
|
IMedicalHistoryMongoDbService medicalHistoryMongoDbService, IDoctorRepository doctorRepository)
|
||||||
@@ -41,28 +41,24 @@ public class MedicalHistoryManageAuthorizationHandler
|
|||||||
|
|
||||||
var documents = await _medicalHistoryMongoDbService.FindAsync<MedicalHistoryAuthorisationModel>(criteria);
|
var documents = await _medicalHistoryMongoDbService.FindAsync<MedicalHistoryAuthorisationModel>(criteria);
|
||||||
if (!documents.Any())
|
if (!documents.Any())
|
||||||
{
|
return new BaseResponse
|
||||||
return new BaseResponse()
|
|
||||||
{
|
{
|
||||||
StatusCode = HttpStatusCodes.NotFound,
|
StatusCode = HttpStatusCodes.NotFound,
|
||||||
Message = "Access to medical history not found.",
|
Message = "Access to medical history not found.",
|
||||||
Data = null
|
Data = null
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
var authorisations = documents[0].Authorisation;
|
var authorisations = documents[0].Authorisation;
|
||||||
if (authorisations.Contains(infoDto.ToString()))
|
if (authorisations.Contains(infoDto.ToString()))
|
||||||
{
|
return new BaseResponse
|
||||||
return new BaseResponse()
|
|
||||||
{
|
{
|
||||||
StatusCode = HttpStatusCodes.Conflict,
|
StatusCode = HttpStatusCodes.Conflict,
|
||||||
Message = "Access to medical history already granted.",
|
Message = "Access to medical history already granted.",
|
||||||
Data = null
|
Data = null
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
authorisations.Add(infoDto.DoctorId.ToString());
|
authorisations.Add(infoDto.DoctorId.ToString());
|
||||||
var authorizationModel = new MedicalHistoryAuthorisationModel()
|
var authorizationModel = new MedicalHistoryAuthorisationModel
|
||||||
{
|
{
|
||||||
Id = infoDto.MedicalRecordId.ToString(),
|
Id = infoDto.MedicalRecordId.ToString(),
|
||||||
Authorisation = authorisations
|
Authorisation = authorisations
|
||||||
@@ -70,7 +66,7 @@ public class MedicalHistoryManageAuthorizationHandler
|
|||||||
|
|
||||||
await _medicalHistoryMongoDbService.ModifyAsync("_id", infoDto.MedicalRecordId.ToString(), authorizationModel);
|
await _medicalHistoryMongoDbService.ModifyAsync("_id", infoDto.MedicalRecordId.ToString(), authorizationModel);
|
||||||
|
|
||||||
return new BaseResponse()
|
return new BaseResponse
|
||||||
{
|
{
|
||||||
StatusCode = HttpStatusCodes.OK,
|
StatusCode = HttpStatusCodes.OK,
|
||||||
Message = "Access to medical history granted.",
|
Message = "Access to medical history granted.",
|
||||||
@@ -102,28 +98,24 @@ public class MedicalHistoryManageAuthorizationHandler
|
|||||||
|
|
||||||
var documents = await _medicalHistoryMongoDbService.FindAsync<MedicalHistoryAuthorisationModel>(criteria);
|
var documents = await _medicalHistoryMongoDbService.FindAsync<MedicalHistoryAuthorisationModel>(criteria);
|
||||||
if (!documents.Any())
|
if (!documents.Any())
|
||||||
{
|
return new BaseResponse
|
||||||
return new BaseResponse()
|
|
||||||
{
|
{
|
||||||
StatusCode = HttpStatusCodes.NotFound,
|
StatusCode = HttpStatusCodes.NotFound,
|
||||||
Message = "Access to medical history not found.",
|
Message = "Access to medical history not found.",
|
||||||
Data = null
|
Data = null
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
var authorisations = documents[0].Authorisation;
|
var authorisations = documents[0].Authorisation;
|
||||||
if (!authorisations.Contains(infoDto.DoctorId.ToString()))
|
if (!authorisations.Contains(infoDto.DoctorId.ToString()))
|
||||||
{
|
return new BaseResponse
|
||||||
return new BaseResponse()
|
|
||||||
{
|
{
|
||||||
StatusCode = HttpStatusCodes.Conflict,
|
StatusCode = HttpStatusCodes.Conflict,
|
||||||
Message = "Access to medical history already revoked.",
|
Message = "Access to medical history already revoked.",
|
||||||
Data = null
|
Data = null
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
authorisations.Remove(infoDto.DoctorId.ToString());
|
authorisations.Remove(infoDto.DoctorId.ToString());
|
||||||
var authorizationModel = new MedicalHistoryAuthorisationModel()
|
var authorizationModel = new MedicalHistoryAuthorisationModel
|
||||||
{
|
{
|
||||||
Id = infoDto.MedicalRecordId.ToString(),
|
Id = infoDto.MedicalRecordId.ToString(),
|
||||||
Authorisation = authorisations
|
Authorisation = authorisations
|
||||||
@@ -131,7 +123,7 @@ public class MedicalHistoryManageAuthorizationHandler
|
|||||||
|
|
||||||
await _medicalHistoryMongoDbService.ModifyAsync("_id", infoDto.MedicalRecordId.ToString(), authorizationModel);
|
await _medicalHistoryMongoDbService.ModifyAsync("_id", infoDto.MedicalRecordId.ToString(), authorizationModel);
|
||||||
|
|
||||||
return new BaseResponse()
|
return new BaseResponse
|
||||||
{
|
{
|
||||||
StatusCode = HttpStatusCodes.OK,
|
StatusCode = HttpStatusCodes.OK,
|
||||||
Message = "Access to medical history granted.",
|
Message = "Access to medical history granted.",
|
||||||
|
|||||||
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|
||||||
namespace Application.Endpoints.MedicalHistories.ManageAuthorization;
|
namespace Application.Endpoints.MedicalHistories.ManageAuthorization;
|
||||||
|
|
||||||
public class MedicalHistoryManageAuthorizationValidation : AbstractValidator<MedicalHistoryManageAuthorizationDoctorDto>
|
public class MedicalHistoryManageAuthorizationValidation : AbstractValidator<MedicalHistoryManageAuthorizationDoctorDto>
|
||||||
{
|
{
|
||||||
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
|
|
||||||
private readonly IDoctorRepository _doctorRepository;
|
private readonly IDoctorRepository _doctorRepository;
|
||||||
|
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
|
||||||
|
|
||||||
public MedicalHistoryManageAuthorizationValidation(IMedicalHistoryRepository medicalHistoryRepository,
|
public MedicalHistoryManageAuthorizationValidation(IMedicalHistoryRepository medicalHistoryRepository,
|
||||||
IDoctorRepository doctorRepository)
|
IDoctorRepository doctorRepository)
|
||||||
|
|||||||
@@ -3,5 +3,5 @@
|
|||||||
public class MedicalHistoryAuthorisationModel
|
public class MedicalHistoryAuthorisationModel
|
||||||
{
|
{
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public List<string> Authorisation { get; set; } = new List<string>();
|
public List<string> Authorisation { get; set; } = new();
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|
||||||
namespace Application.Endpoints.MedicalHistories;
|
namespace Application.Endpoints.MedicalHistories;
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.MongoDB;
|
||||||
using Application.Services.Database.MongoDB;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Core.Entities;
|
using Core.Entities;
|
||||||
|
|
||||||
namespace Application.Endpoints.MedicalHistories;
|
namespace Application.Endpoints.MedicalHistories;
|
||||||
|
|
||||||
public class MedicalHistoryHandler
|
public class MedicalHistoryHandler
|
||||||
{
|
{
|
||||||
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
|
|
||||||
private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService;
|
private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService;
|
||||||
|
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
|
||||||
private readonly IPatientRepository _patientRepository;
|
private readonly IPatientRepository _patientRepository;
|
||||||
|
|
||||||
public MedicalHistoryHandler(IMedicalHistoryRepository medicalHistoryRepository,
|
public MedicalHistoryHandler(IMedicalHistoryRepository medicalHistoryRepository,
|
||||||
@@ -80,7 +80,7 @@ public class MedicalHistoryHandler
|
|||||||
UserId = medicalHistoryCreateDto.UserId,
|
UserId = medicalHistoryCreateDto.UserId,
|
||||||
Content = medicalHistoryCreateDto.Content
|
Content = medicalHistoryCreateDto.Content
|
||||||
};
|
};
|
||||||
|
|
||||||
var medicalHistoryId = medicalHistory.Id;
|
var medicalHistoryId = medicalHistory.Id;
|
||||||
var newMedicalHistory = new MedicalHistoryAuthorisationModel
|
var newMedicalHistory = new MedicalHistoryAuthorisationModel
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|
||||||
namespace Application.Endpoints.MedicalHistories;
|
namespace Application.Endpoints.MedicalHistories;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
|
|
||||||
namespace Application.Endpoints.Patients.Login;
|
namespace Application.Endpoints.Patients.Login;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|
||||||
namespace Application.Endpoints.Patients.Login;
|
namespace Application.Endpoints.Patients.Login;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Application.Services.HashingAlgorithms;
|
using Application.Services.HashingAlgorithms;
|
||||||
|
|
||||||
namespace Application.Endpoints.Patients.Profile;
|
namespace Application.Endpoints.Patients.Profile;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|
||||||
namespace Application.Endpoints.Patients.Profile;
|
namespace Application.Endpoints.Patients.Profile;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Application.Services.HashingAlgorithms;
|
using Application.Services.HashingAlgorithms;
|
||||||
using Core.Entities;
|
using Core.Entities;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|
||||||
namespace Application.Endpoints.Patients.Registration;
|
namespace Application.Endpoints.Patients.Registration;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Application.Services.HashingAlgorithms;
|
using Application.Services.HashingAlgorithms;
|
||||||
|
|
||||||
namespace Application.Endpoints.Patients.ResetPassword;
|
namespace Application.Endpoints.Patients.ResetPassword;
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|
||||||
namespace Application.Endpoints.Patients.ResetPassword;
|
namespace Application.Endpoints.Patients.ResetPassword;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public interface IAppointmentsMongoDbService
|
|||||||
Task ModifyAsync<T>(string keyField, string keyValue, T document);
|
Task ModifyAsync<T>(string keyField, string keyValue, T document);
|
||||||
|
|
||||||
Task DeleteAsync<T>(string keyField, string keyValue);
|
Task DeleteAsync<T>(string keyField, string keyValue);
|
||||||
|
|
||||||
Task DeleteByIdAsync<T>(string id);
|
Task DeleteByIdAsync<T>(string id);
|
||||||
|
|
||||||
public Task<bool> IsAppointmentUnique(AppointmentManagementDto dto);
|
public Task<bool> IsAppointmentUnique(AppointmentManagementDto dto);
|
||||||
|
|||||||
@@ -13,6 +13,6 @@ public interface IChatMongoDbService
|
|||||||
Task ModifyAsync<T>(string keyField, string keyValue, T document);
|
Task ModifyAsync<T>(string keyField, string keyValue, T document);
|
||||||
|
|
||||||
Task DeleteAsync<T>(string keyField, string keyValue);
|
Task DeleteAsync<T>(string keyField, string keyValue);
|
||||||
|
|
||||||
Task DeleteByIdAsync<T>(string id);
|
Task DeleteByIdAsync<T>(string id);
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using Application.Endpoints.MedicalHistories;
|
using MongoDB.Driver;
|
||||||
using MongoDB.Driver;
|
|
||||||
|
|
||||||
namespace Application.Services.Database.MongoDB;
|
namespace Application.Services.Database.MongoDB;
|
||||||
|
|
||||||
@@ -14,6 +13,6 @@ public interface IMedicalHistoryMongoDbService
|
|||||||
Task ModifyAsync<T>(string keyField, string keyValue, T document);
|
Task ModifyAsync<T>(string keyField, string keyValue, T document);
|
||||||
|
|
||||||
Task DeleteAsync<T>(string keyField, string keyValue);
|
Task DeleteAsync<T>(string keyField, string keyValue);
|
||||||
|
|
||||||
Task DeleteByIdAsync<T>(string id);
|
Task DeleteByIdAsync<T>(string id);
|
||||||
}
|
}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
namespace Application.Services.Database;
|
|
||||||
|
|
||||||
public interface IConversationRepository
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using Core.Entities;
|
using Core.Entities;
|
||||||
|
|
||||||
namespace Application.Services.Database;
|
namespace Application.Services.Database.PostgreSQL;
|
||||||
|
|
||||||
public interface IDoctorRepository
|
public interface IDoctorRepository
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using Core.Entities;
|
using Core.Entities;
|
||||||
|
|
||||||
namespace Application.Services.Database;
|
namespace Application.Services.Database.PostgreSQL;
|
||||||
|
|
||||||
public interface IMedicalHistoryRepository
|
public interface IMedicalHistoryRepository
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using Core.Entities;
|
using Core.Entities;
|
||||||
|
|
||||||
namespace Application.Services.Database;
|
namespace Application.Services.Database.PostgreSQL;
|
||||||
|
|
||||||
public interface IPatientRepository
|
public interface IPatientRepository
|
||||||
{
|
{
|
||||||
@@ -10,9 +10,9 @@ public interface IPatientRepository
|
|||||||
|
|
||||||
Task<Patient?> FindByEmailAsync(string email);
|
Task<Patient?> FindByEmailAsync(string email);
|
||||||
|
|
||||||
Task UpdateAsync(Patient doctor);
|
Task UpdateAsync(Patient patient);
|
||||||
|
|
||||||
Task DeleteAsync(Patient doctor);
|
Task DeleteAsync(Patient patient);
|
||||||
|
|
||||||
Task<IEnumerable<Patient>> GetAllAsync();
|
Task<IEnumerable<Patient>> GetAllAsync();
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
using System.Security.Claims;
|
namespace Application.Services.Jwt;
|
||||||
|
|
||||||
namespace Application.Services.Jwt;
|
|
||||||
|
|
||||||
public interface IJwtService
|
public interface IJwtService
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,25 +6,38 @@ public class Appointment
|
|||||||
{
|
{
|
||||||
AppointmentsList = new List<DateTime>();
|
AppointmentsList = new List<DateTime>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Id { get; private set; }
|
public string Id { get; private set; }
|
||||||
public string PatientId { get; private set; }
|
public string PatientId { get; private set; }
|
||||||
public string DoctorId { get; private set; }
|
public string DoctorId { get; private set; }
|
||||||
public List<DateTime> AppointmentsList { get; private set; }
|
public List<DateTime> AppointmentsList { get; }
|
||||||
|
|
||||||
|
public void SetId(string id)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPatientId(string patientId)
|
||||||
|
{
|
||||||
|
PatientId = patientId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetDoctorIid(string doctorId)
|
||||||
|
{
|
||||||
|
DoctorId = doctorId;
|
||||||
|
}
|
||||||
|
|
||||||
public void SetId(string id) { Id = id; }
|
|
||||||
public void SetPatientId(string patientId) { PatientId = patientId; }
|
|
||||||
public void SetDoctorIid(string doctorId) { DoctorId = doctorId; }
|
|
||||||
|
|
||||||
public void AddAppointment(DateTime appointmentDate)
|
public void AddAppointment(DateTime appointmentDate)
|
||||||
{
|
{
|
||||||
DateTime utcAppointmentDate = new DateTime(appointmentDate.Year, appointmentDate.Month, appointmentDate.Day, 0, 0, 0, DateTimeKind.Utc);
|
var utcAppointmentDate = new DateTime(appointmentDate.Year, appointmentDate.Month, appointmentDate.Day, 0, 0, 0,
|
||||||
|
DateTimeKind.Utc);
|
||||||
AppointmentsList.Add(utcAppointmentDate);
|
AppointmentsList.Add(utcAppointmentDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveAppointment(DateTime appointmentDate)
|
public void RemoveAppointment(DateTime appointmentDate)
|
||||||
{
|
{
|
||||||
DateTime utcAppointmentDate = new DateTime(appointmentDate.Year, appointmentDate.Month, appointmentDate.Day, 0, 0, 0, DateTimeKind.Utc);
|
var utcAppointmentDate = new DateTime(appointmentDate.Year, appointmentDate.Month, appointmentDate.Day, 0, 0, 0,
|
||||||
|
DateTimeKind.Utc);
|
||||||
AppointmentsList.Remove(utcAppointmentDate);
|
AppointmentsList.Remove(utcAppointmentDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,8 +8,15 @@ public class Chat
|
|||||||
public string Id { get; private set; }
|
public string Id { get; private set; }
|
||||||
public List<Message> Messages { get; private set; } = new();
|
public List<Message> Messages { get; private set; } = new();
|
||||||
|
|
||||||
public void SetId(string id) { Id = id; }
|
public void SetId(string id)
|
||||||
public void SetMessages(List<Message> messages) { Messages = messages; }
|
{
|
||||||
|
Id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetMessages(List<Message> messages)
|
||||||
|
{
|
||||||
|
Messages = messages;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Message
|
public class Message
|
||||||
@@ -19,12 +26,18 @@ public class Message
|
|||||||
UserId = userId;
|
UserId = userId;
|
||||||
Content = content;
|
Content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BsonRepresentation(BsonType.String)]
|
[BsonRepresentation(BsonType.String)] public Guid UserId { get; private set; }
|
||||||
public Guid UserId { get; private set; }
|
|
||||||
|
|
||||||
public string Content { get; private set; }
|
public string Content { get; private set; }
|
||||||
|
|
||||||
public void SetUserId(Guid userId) { UserId = userId; }
|
public void SetUserId(Guid userId)
|
||||||
public void SetContent(string content) { Content = content; }
|
{
|
||||||
|
UserId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetContent(string content)
|
||||||
|
{
|
||||||
|
Content = content;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -16,10 +16,10 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0"/>
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0"/>
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0"/>
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0"/>
|
||||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0"/>
|
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0"/>
|
||||||
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="7.5.1" />
|
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="7.5.1"/>
|
||||||
<PackageReference Include="MongoDB.Driver" Version="2.24.0"/>
|
<PackageReference Include="MongoDB.Driver" Version="2.24.0"/>
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2"/>
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2"/>
|
||||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.MongoDB;
|
||||||
using Application.Services.Database.MongoDB;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Application.Services.HashingAlgorithms;
|
using Application.Services.HashingAlgorithms;
|
||||||
using Application.Services.Jwt;
|
using Application.Services.Jwt;
|
||||||
|
|
||||||
using Infrastructure.Data;
|
using Infrastructure.Data;
|
||||||
using Infrastructure.Services.HashingAlgorithms;
|
using Infrastructure.Services.HashingAlgorithms;
|
||||||
using Infrastructure.Services.MongoDB;
|
using Infrastructure.Services.MongoDB;
|
||||||
using Infrastructure.Services.PostgreSQL;
|
using Infrastructure.Services.PostgreSQL;
|
||||||
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using MongoDB.Driver;
|
|
||||||
|
|
||||||
namespace Infrastructure;
|
namespace Infrastructure;
|
||||||
|
|
||||||
@@ -38,7 +35,7 @@ public static class DependencyInjection
|
|||||||
|
|
||||||
return new MedicalHistoryMongoDbService(connectionString, databaseName, collectionName);
|
return new MedicalHistoryMongoDbService(connectionString, databaseName, collectionName);
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddSingleton<IChatMongoDbService>(serviceProvider =>
|
services.AddSingleton<IChatMongoDbService>(serviceProvider =>
|
||||||
{
|
{
|
||||||
var configuration = serviceProvider.GetRequiredService<IConfiguration>();
|
var configuration = serviceProvider.GetRequiredService<IConfiguration>();
|
||||||
@@ -48,7 +45,7 @@ public static class DependencyInjection
|
|||||||
|
|
||||||
return new ChatMongoDbService(connectionString, databaseName, collectionName);
|
return new ChatMongoDbService(connectionString, databaseName, collectionName);
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddSingleton<IAppointmentsMongoDbService>(serviceProvider =>
|
services.AddSingleton<IAppointmentsMongoDbService>(serviceProvider =>
|
||||||
{
|
{
|
||||||
var configuration = serviceProvider.GetRequiredService<IConfiguration>();
|
var configuration = serviceProvider.GetRequiredService<IConfiguration>();
|
||||||
@@ -58,19 +55,18 @@ public static class DependencyInjection
|
|||||||
|
|
||||||
return new AppointmentsMongoDbService(connectionString, databaseName, collectionName);
|
return new AppointmentsMongoDbService(connectionString, databaseName, collectionName);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Other Services
|
// Other Services
|
||||||
services.AddScoped<IHashingAlgorithms, HashingAlgorithms>();
|
services.AddScoped<IHashingAlgorithms, HashingAlgorithms>();
|
||||||
|
|
||||||
services.AddSingleton<IJwtService, JwtService>(serviceProvider =>
|
services.AddSingleton<IJwtService, JwtService>(serviceProvider =>
|
||||||
{
|
{
|
||||||
var configuration = serviceProvider.GetRequiredService<IConfiguration>();
|
var configuration = serviceProvider.GetRequiredService<IConfiguration>();
|
||||||
return new JwtService(configuration);
|
return new JwtService(configuration);
|
||||||
});
|
});
|
||||||
|
|
||||||
// services.AddScoped<IEmailService, EmailService>();
|
// services.AddScoped<IEmailService, EmailService>();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,16 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
|
||||||
using System;
|
|
||||||
using System.IdentityModel.Tokens.Jwt;
|
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Application.Services.Jwt;
|
using Application.Services.Jwt;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
|
||||||
public class JwtService : IJwtService
|
public class JwtService : IJwtService
|
||||||
{
|
{
|
||||||
private readonly string _secretKey;
|
|
||||||
private readonly string _issuer;
|
|
||||||
private readonly string _audience;
|
private readonly string _audience;
|
||||||
private readonly double _expiryMinutes;
|
private readonly double _expiryMinutes;
|
||||||
|
private readonly string _issuer;
|
||||||
|
private readonly string _secretKey;
|
||||||
|
|
||||||
public JwtService(IConfiguration configuration)
|
public JwtService(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
@@ -34,13 +33,14 @@ public class JwtService : IJwtService
|
|||||||
Expires = DateTime.UtcNow.AddMinutes(_expiryMinutes),
|
Expires = DateTime.UtcNow.AddMinutes(_expiryMinutes),
|
||||||
Issuer = _issuer,
|
Issuer = _issuer,
|
||||||
Audience = _audience,
|
Audience = _audience,
|
||||||
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
|
SigningCredentials =
|
||||||
|
new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
|
||||||
};
|
};
|
||||||
|
|
||||||
var token = tokenHandler.CreateToken(tokenDescriptor);
|
var token = tokenHandler.CreateToken(tokenDescriptor);
|
||||||
return tokenHandler.WriteToken(token);
|
return tokenHandler.WriteToken(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ValidateJwtToken(string token)
|
public bool ValidateJwtToken(string token)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(token))
|
if (string.IsNullOrWhiteSpace(token))
|
||||||
@@ -58,9 +58,9 @@ public class JwtService : IJwtService
|
|||||||
ValidateAudience = true,
|
ValidateAudience = true,
|
||||||
ValidIssuer = _issuer,
|
ValidIssuer = _issuer,
|
||||||
ValidAudience = _audience,
|
ValidAudience = _audience,
|
||||||
ClockSkew = TimeSpan.Zero,
|
ClockSkew = TimeSpan.Zero
|
||||||
}, out SecurityToken validatedToken);
|
}, out var validatedToken);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@@ -68,20 +68,14 @@ public class JwtService : IJwtService
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string RefreshToken(string token)
|
public string RefreshToken(string token)
|
||||||
{
|
{
|
||||||
var principal = ValidateTokenAndGetPrincipal(token);
|
var principal = ValidateTokenAndGetPrincipal(token);
|
||||||
if (principal == null)
|
if (principal == null) throw new SecurityTokenException("Invalid token.");
|
||||||
{
|
|
||||||
throw new SecurityTokenException("Invalid token.");
|
|
||||||
}
|
|
||||||
|
|
||||||
var emailClaim = principal.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email);
|
var emailClaim = principal.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email);
|
||||||
if (emailClaim == null)
|
if (emailClaim == null) throw new SecurityTokenException("Token does not contain an email claim.");
|
||||||
{
|
|
||||||
throw new SecurityTokenException("Token does not contain an email claim.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return GenerateJwtToken(emailClaim.Value);
|
return GenerateJwtToken(emailClaim.Value);
|
||||||
}
|
}
|
||||||
@@ -100,7 +94,7 @@ public class JwtService : IJwtService
|
|||||||
ValidateAudience = true,
|
ValidateAudience = true,
|
||||||
ValidIssuer = _issuer,
|
ValidIssuer = _issuer,
|
||||||
ValidAudience = _audience,
|
ValidAudience = _audience,
|
||||||
ClockSkew = TimeSpan.Zero,
|
ClockSkew = TimeSpan.Zero
|
||||||
}, out _);
|
}, out _);
|
||||||
|
|
||||||
return principal;
|
return principal;
|
||||||
@@ -111,5 +105,4 @@ public class JwtService : IJwtService
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -14,46 +14,38 @@ public class AppointmentsMongoDbService : MongoDbService, IAppointmentsMongoDbSe
|
|||||||
public async Task<bool> IsAppointmentUnique(AppointmentManagementDto dto)
|
public async Task<bool> IsAppointmentUnique(AppointmentManagementDto dto)
|
||||||
{
|
{
|
||||||
var appointment = dto.Appointment.ToUniversalTime();
|
var appointment = dto.Appointment.ToUniversalTime();
|
||||||
|
|
||||||
var criteria = new List<(string FieldName, string Value)>
|
var criteria = new List<(string FieldName, string Value)>
|
||||||
{
|
{
|
||||||
("DoctorId", dto.DoctorId.ToString()),
|
("DoctorId", dto.DoctorId.ToString()),
|
||||||
("PatientId", dto.PatientId.ToString())
|
("PatientId", dto.PatientId.ToString())
|
||||||
};
|
};
|
||||||
|
|
||||||
var appointments = await FindAsync<Appointment>(criteria);
|
var appointments = await FindAsync<Appointment>(criteria);
|
||||||
|
|
||||||
foreach (var app in appointments)
|
foreach (var app in appointments)
|
||||||
{
|
|
||||||
if (app.AppointmentsList.Any(a => a.Date == appointment.Date))
|
if (app.AppointmentsList.Any(a => a.Date == appointment.Date))
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> DoesAppointmentExists(AppointmentManagementDto dto)
|
public async Task<bool> DoesAppointmentExists(AppointmentManagementDto dto)
|
||||||
{
|
{
|
||||||
var appointment = dto.Appointment.ToUniversalTime();
|
var appointment = dto.Appointment.ToUniversalTime();
|
||||||
|
|
||||||
var criteria = new List<(string FieldName, string Value)>
|
var criteria = new List<(string FieldName, string Value)>
|
||||||
{
|
{
|
||||||
("DoctorId", dto.DoctorId.ToString()),
|
("DoctorId", dto.DoctorId.ToString()),
|
||||||
("PatientId", dto.PatientId.ToString())
|
("PatientId", dto.PatientId.ToString())
|
||||||
};
|
};
|
||||||
|
|
||||||
var appointments = await FindAsync<Appointment>(criteria);
|
var appointments = await FindAsync<Appointment>(criteria);
|
||||||
|
|
||||||
foreach (var app in appointments)
|
foreach (var app in appointments)
|
||||||
{
|
|
||||||
if (app.AppointmentsList.Any(a => a.Date == appointment.Date))
|
if (app.AppointmentsList.Any(a => a.Date == appointment.Date))
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,81 +1,79 @@
|
|||||||
using Application.Services.Database;
|
using MongoDB.Bson;
|
||||||
using MongoDB.Driver;
|
using MongoDB.Driver;
|
||||||
using MongoDB.Bson;
|
|
||||||
|
|
||||||
namespace Infrastructure.Services.MongoDB
|
namespace Infrastructure.Services.MongoDB;
|
||||||
|
|
||||||
|
public class MongoDbService
|
||||||
{
|
{
|
||||||
public class MongoDbService
|
private readonly string _collectionName;
|
||||||
|
private readonly IMongoClient _database;
|
||||||
|
private readonly string _databaseName;
|
||||||
|
|
||||||
|
public MongoDbService(string connectionString, string databaseName, string collectionName)
|
||||||
{
|
{
|
||||||
private readonly IMongoClient _database;
|
_databaseName = databaseName;
|
||||||
private readonly string _databaseName;
|
_collectionName = collectionName;
|
||||||
private readonly string _collectionName;
|
|
||||||
|
|
||||||
public MongoDbService(string connectionString, string databaseName, string collectionName)
|
Console.WriteLine($"Connection string: {connectionString}");
|
||||||
|
Console.WriteLine($"Database Name: {databaseName}");
|
||||||
|
Console.WriteLine($"Collection Name: {collectionName}");
|
||||||
|
|
||||||
|
var settings = MongoClientSettings.FromConnectionString(connectionString);
|
||||||
|
settings.ServerApi = new ServerApi(ServerApiVersion.V1);
|
||||||
|
_database = new MongoClient(settings);
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
_databaseName = databaseName;
|
var result = _database.GetDatabase("admin").RunCommand<BsonDocument>(new BsonDocument("ping", 1));
|
||||||
_collectionName = collectionName;
|
Console.WriteLine("Pinged your deployment. You successfully connected to MongoDB!");
|
||||||
|
|
||||||
Console.WriteLine($"Connection string: {connectionString}");
|
|
||||||
Console.WriteLine($"Database Name: {databaseName}");
|
|
||||||
Console.WriteLine($"Collection Name: {collectionName}");
|
|
||||||
|
|
||||||
var settings = MongoClientSettings.FromConnectionString(connectionString);
|
|
||||||
settings.ServerApi = new ServerApi(ServerApiVersion.V1);
|
|
||||||
_database = new MongoClient(settings);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var result = _database.GetDatabase("admin").RunCommand<BsonDocument>(new BsonDocument("ping", 1));
|
|
||||||
Console.WriteLine("Pinged your deployment. You successfully connected to MongoDB!");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
public IMongoCollection<T> GetCollection<T>()
|
|
||||||
{
|
{
|
||||||
return _database.GetDatabase(_databaseName).GetCollection<T>(_collectionName);
|
Console.WriteLine(ex);
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<List<T>> FindAsync<T>(List<(string FieldName, string Value)> criteria)
|
|
||||||
{
|
|
||||||
var collection = _database.GetDatabase(_databaseName).GetCollection<T>(_collectionName);
|
|
||||||
|
|
||||||
var filters = new List<FilterDefinition<T>>();
|
|
||||||
foreach (var (FieldName, Value) in criteria) filters.Add(Builders<T>.Filter.Eq(FieldName, Value));
|
|
||||||
|
|
||||||
var combinedFilter = Builders<T>.Filter.And(filters);
|
|
||||||
|
|
||||||
return await collection.Find(combinedFilter).ToListAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task AddAsync<T>(T document)
|
|
||||||
{
|
|
||||||
var collection = _database.GetDatabase(_databaseName).GetCollection<T>(_collectionName);
|
|
||||||
await collection.InsertOneAsync(document);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task ModifyAsync<T>(string keyField, string keyValue, T document)
|
|
||||||
{
|
|
||||||
var collection = _database.GetDatabase(_databaseName).GetCollection<T>(_collectionName);
|
|
||||||
var filter = Builders<T>.Filter.Eq(keyField, keyValue);
|
|
||||||
await collection.ReplaceOneAsync(filter, document, new ReplaceOptions { IsUpsert = true });
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task DeleteAsync<T>(string keyField, string keyValue)
|
|
||||||
{
|
|
||||||
var collection = _database.GetDatabase(_databaseName).GetCollection<T>(_collectionName);
|
|
||||||
var filter = Builders<T>.Filter.Eq(keyField, keyValue);
|
|
||||||
await collection.DeleteOneAsync(filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task DeleteByIdAsync<T>(string id)
|
|
||||||
{
|
|
||||||
var collection = _database.GetDatabase(_databaseName).GetCollection<T>(_collectionName);
|
|
||||||
var filter = Builders<T>.Filter.Eq("_id", id);
|
|
||||||
await collection.DeleteOneAsync(filter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IMongoCollection<T> GetCollection<T>()
|
||||||
|
{
|
||||||
|
return _database.GetDatabase(_databaseName).GetCollection<T>(_collectionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<T>> FindAsync<T>(List<(string FieldName, string Value)> criteria)
|
||||||
|
{
|
||||||
|
var collection = _database.GetDatabase(_databaseName).GetCollection<T>(_collectionName);
|
||||||
|
|
||||||
|
var filters = new List<FilterDefinition<T>>();
|
||||||
|
foreach (var (FieldName, Value) in criteria) filters.Add(Builders<T>.Filter.Eq(FieldName, Value));
|
||||||
|
|
||||||
|
var combinedFilter = Builders<T>.Filter.And(filters);
|
||||||
|
|
||||||
|
return await collection.Find(combinedFilter).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task AddAsync<T>(T document)
|
||||||
|
{
|
||||||
|
var collection = _database.GetDatabase(_databaseName).GetCollection<T>(_collectionName);
|
||||||
|
await collection.InsertOneAsync(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task ModifyAsync<T>(string keyField, string keyValue, T document)
|
||||||
|
{
|
||||||
|
var collection = _database.GetDatabase(_databaseName).GetCollection<T>(_collectionName);
|
||||||
|
var filter = Builders<T>.Filter.Eq(keyField, keyValue);
|
||||||
|
await collection.ReplaceOneAsync(filter, document, new ReplaceOptions { IsUpsert = true });
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DeleteAsync<T>(string keyField, string keyValue)
|
||||||
|
{
|
||||||
|
var collection = _database.GetDatabase(_databaseName).GetCollection<T>(_collectionName);
|
||||||
|
var filter = Builders<T>.Filter.Eq(keyField, keyValue);
|
||||||
|
await collection.DeleteOneAsync(filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DeleteByIdAsync<T>(string id)
|
||||||
|
{
|
||||||
|
var collection = _database.GetDatabase(_databaseName).GetCollection<T>(_collectionName);
|
||||||
|
var filter = Builders<T>.Filter.Eq("_id", id);
|
||||||
|
await collection.DeleteOneAsync(filter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Core.Entities;
|
using Core.Entities;
|
||||||
using Infrastructure.Data;
|
using Infrastructure.Data;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Core.Entities;
|
using Core.Entities;
|
||||||
using Infrastructure.Data;
|
using Infrastructure.Data;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Application.Services.Database;
|
using Application.Services.Database.PostgreSQL;
|
||||||
using Core.Entities;
|
using Core.Entities;
|
||||||
using Infrastructure.Data;
|
using Infrastructure.Data;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Infrastructure")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("Infrastructure")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8663a186a056b0dfbfeebf9ae16be42b40101093")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+13bfa2bdd901a8b258d4cf881b5bb079066ab1c6")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("Infrastructure")]
|
[assembly: System.Reflection.AssemblyProductAttribute("Infrastructure")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("Infrastructure")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("Infrastructure")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
90add3a549a5ad86ae4df2628a148c5a9756bdaa56fd8988b963942aa2b42329
|
30fec65cc45becf276dcf8ed6696bf02cadfb1a90989db6bf5e21ba21d2c8f27
|
||||||
|
|||||||
Reference in New Issue
Block a user