diff --git a/backend/API/API.csproj b/backend/API/API.csproj index 5dceddc..a9edf31 100644 --- a/backend/API/API.csproj +++ b/backend/API/API.csproj @@ -8,7 +8,7 @@ - + diff --git a/backend/API/Controllers/AppointmentsController.cs b/backend/API/Controllers/AppointmentsController.cs index dc10ef5..20a598a 100644 --- a/backend/API/Controllers/AppointmentsController.cs +++ b/backend/API/Controllers/AppointmentsController.cs @@ -1,7 +1,7 @@ using Application.Endpoints; using Application.Endpoints.Appointments; -using Application.Services.Database; using Application.Services.Database.MongoDB; +using Application.Services.Database.PostgreSQL; using Microsoft.AspNetCore.Mvc; namespace API.Controllers; @@ -9,8 +9,8 @@ namespace API.Controllers; public class AppointmentsController : BaseApiController { private readonly IAppointmentsMongoDbService _appointmentsMongoDbService; - private readonly IPatientRepository _patientRepository; private readonly IDoctorRepository _doctorRepository; + private readonly IPatientRepository _patientRepository; public AppointmentsController(IAppointmentsMongoDbService appointmentsMongoDbService, IPatientRepository patientRepository, IDoctorRepository doctorRepository) @@ -23,7 +23,8 @@ public class AppointmentsController : BaseApiController [HttpPost] public async Task> 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); return StatusCode(response.StatusCode, response); } @@ -31,7 +32,8 @@ public class AppointmentsController : BaseApiController [HttpDelete] public async Task> 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); return StatusCode(response.StatusCode, response); } diff --git a/backend/API/Controllers/ChatController.cs b/backend/API/Controllers/ChatController.cs index bd3128d..f27f92b 100644 --- a/backend/API/Controllers/ChatController.cs +++ b/backend/API/Controllers/ChatController.cs @@ -1,7 +1,7 @@ using Application.Endpoints; using Application.Endpoints.Chats; -using Application.Services.Database; using Application.Services.Database.MongoDB; +using Application.Services.Database.PostgreSQL; using Microsoft.AspNetCore.Mvc; namespace API.Controllers; @@ -9,8 +9,8 @@ namespace API.Controllers; public class ChatController : BaseApiController { private readonly IChatMongoDbService _chatMongoDbService; - private readonly IPatientRepository _patientRepository; private readonly IDoctorRepository _doctorRepository; + private readonly IPatientRepository _patientRepository; public ChatController(IChatMongoDbService chatMongoDbService, IPatientRepository patientRepository, IDoctorRepository doctorRepository) @@ -19,7 +19,7 @@ public class ChatController : BaseApiController _patientRepository = patientRepository; _doctorRepository = doctorRepository; } - + [HttpPost("send_message")] public async Task> SendMessage(SendMessageDto sendMessageDto) { @@ -27,7 +27,7 @@ public class ChatController : BaseApiController var response = await handler.HandleSendMessage(sendMessageDto).ConfigureAwait(false); return StatusCode(response.StatusCode, response); } - + [HttpPost("get_conversation")] public async Task> GetConversation(GetConversationDto getConversationDto) { diff --git a/backend/API/Controllers/DoctorsController.cs b/backend/API/Controllers/DoctorsController.cs index 1d47388..43df1d7 100644 --- a/backend/API/Controllers/DoctorsController.cs +++ b/backend/API/Controllers/DoctorsController.cs @@ -3,8 +3,8 @@ using Application.Endpoints.Doctors.Login; using Application.Endpoints.Doctors.Profile; using Application.Endpoints.Doctors.Registration; using Application.Endpoints.Doctors.ResetPassword; -using Application.Services.Database; using Application.Services.Database.MongoDB; +using Application.Services.Database.PostgreSQL; using Application.Services.HashingAlgorithms; using Application.Services.Jwt; using Core.Entities; @@ -16,10 +16,10 @@ namespace API.Controllers; [Route("api/[controller]")] public class DoctorsController : ControllerBase { + private readonly IAppointmentsMongoDbService _appointmentsMongoDbService; private readonly IDoctorRepository _database; private readonly IHashingAlgorithms _hashingAlgorithms; private readonly IJwtService _jwtService; - private readonly IAppointmentsMongoDbService _appointmentsMongoDbService; public DoctorsController(IDoctorRepository database, IHashingAlgorithms hashingAlgorithms, IJwtService jwtService, IAppointmentsMongoDbService appointmentsMongoDbService) @@ -48,11 +48,11 @@ public class DoctorsController : ControllerBase { Doctor doctor = (Doctor)response.Data; var authToken = _jwtService.GenerateJwtToken(doctor.Email); - + HttpContext.Response.Headers.Add("Authorization", $"Bearer {authToken}"); } */ - + return StatusCode(response.StatusCode, response); } @@ -61,36 +61,30 @@ public class DoctorsController : ControllerBase { var authorizationHeader = Request.Headers["Authorization"].FirstOrDefault(); if (string.IsNullOrEmpty(authorizationHeader) || !authorizationHeader.StartsWith("Bearer ")) - { return StatusCode(HttpStatusCodes.BadRequest, new BaseResponse { - StatusCode = HttpStatusCodes.BadRequest, + StatusCode = HttpStatusCodes.BadRequest, Message = "Invalid request header format.", Data = null }); - } var oldToken = authorizationHeader.Substring("Bearer ".Length).Trim(); - + if (!_jwtService.ValidateJwtToken(oldToken)) - { return StatusCode(HttpStatusCodes.Unauthorized, new BaseResponse { - StatusCode = HttpStatusCodes.Unauthorized, - Message = "Invalid JWT token.", + StatusCode = HttpStatusCodes.Unauthorized, + Message = "Invalid JWT token.", Data = null }); - } - else + + var newToken = _jwtService.RefreshToken(oldToken); + return StatusCode(HttpStatusCodes.OK, new BaseResponse { - var newToken = _jwtService.RefreshToken(oldToken); - return StatusCode(HttpStatusCodes.OK, new BaseResponse - { - StatusCode = HttpStatusCodes.OK, - Message = "Token refreshed successfully.", - Data = new { Token = newToken } - }); - } + StatusCode = HttpStatusCodes.OK, + Message = "Token refreshed successfully.", + Data = new { Token = newToken } + }); } [HttpPost("reset_password")] @@ -131,11 +125,8 @@ public class DoctorsController : ControllerBase var handler = new DoctorProfileHandler(_database, _hashingAlgorithms); var response = await handler.HandleDelete(id).ConfigureAwait(false); - if (response.StatusCode < HttpStatusCodes.BadRequest) - { - DeleteDoctorAppointments(id); - } - + if (response.StatusCode < HttpStatusCodes.BadRequest) DeleteDoctorAppointments(id); + return StatusCode(response.StatusCode, response); } @@ -146,10 +137,7 @@ public class DoctorsController : ControllerBase ("DoctorId", doctorId.ToString()) }; var appointments = await _appointmentsMongoDbService.FindAsync(criteria); - if (!appointments.Any()) - { - return; - } + if (!appointments.Any()) return; await _appointmentsMongoDbService.DeleteByIdAsync(appointments[0].Id); } } \ No newline at end of file diff --git a/backend/API/Controllers/MedicalHistoryController.cs b/backend/API/Controllers/MedicalHistoryController.cs index d303b08..9a79e4b 100644 --- a/backend/API/Controllers/MedicalHistoryController.cs +++ b/backend/API/Controllers/MedicalHistoryController.cs @@ -1,8 +1,8 @@ using Application.Endpoints; using Application.Endpoints.MedicalHistories.FileManagement; using Application.Endpoints.MedicalHistories.ManageAuthorization; -using Application.Services.Database; using Application.Services.Database.MongoDB; +using Application.Services.Database.PostgreSQL; using Microsoft.AspNetCore.Mvc; namespace API.Controllers; @@ -11,10 +11,10 @@ namespace API.Controllers; [Route("api/[controller]")] public class MedicalHistoryController : ControllerBase { - private readonly IMedicalHistoryRepository _medicalHistoryRepository; - private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService; - private readonly IPatientRepository _patientRepository; private readonly IDoctorRepository _doctorRepository; + private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService; + private readonly IMedicalHistoryRepository _medicalHistoryRepository; + private readonly IPatientRepository _patientRepository; public MedicalHistoryController(IMedicalHistoryRepository medicalHistoryRepository, IPatientRepository patientRepository, IMedicalHistoryMongoDbService mongoDbService, @@ -81,7 +81,7 @@ public class MedicalHistoryController : ControllerBase var response = await handler.HandleGrantDoctorAccess(infoDto); return StatusCode(response.StatusCode, response); } - + [HttpPut("revoke_access")] public async Task> RevokeAccessToMedicalHistory( MedicalHistoryManageAuthorizationDoctorDto infoDto) diff --git a/backend/API/Controllers/PatientsController.cs b/backend/API/Controllers/PatientsController.cs index 392e860..bcca422 100644 --- a/backend/API/Controllers/PatientsController.cs +++ b/backend/API/Controllers/PatientsController.cs @@ -3,10 +3,9 @@ using Application.Endpoints.Patients.Login; using Application.Endpoints.Patients.Profile; using Application.Endpoints.Patients.Registration; using Application.Endpoints.Patients.ResetPassword; -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using Application.Services.HashingAlgorithms; using Application.Services.Jwt; -using Core.Entities; using Microsoft.AspNetCore.Mvc; namespace API.Controllers; @@ -16,15 +15,17 @@ namespace API.Controllers; public class PatientsController : ControllerBase { private readonly IHashingAlgorithms _hashingAlgorithms; - private readonly IPatientRepository _patientRepository; private readonly IJwtService _jwtService; + private readonly IMedicalHistoryRepository _medicalHistory; + private readonly IPatientRepository _patientRepository; public PatientsController(IPatientRepository patientRepository, IHashingAlgorithms hashingAlgorithms, - IJwtService jwtService) + IJwtService jwtService, IMedicalHistoryRepository medicalHistory) { _patientRepository = patientRepository; _hashingAlgorithms = hashingAlgorithms; _jwtService = jwtService; + _medicalHistory = medicalHistory; } [HttpGet] @@ -53,48 +54,42 @@ public class PatientsController : ControllerBase { Patient patient = (Patient)response.Data; var authToken = _jwtService.GenerateJwtToken(patient.Email); - + HttpContext.Response.Headers.Add("Authorization", $"Bearer {authToken}"); } */ return StatusCode(response.StatusCode, response); } - + [HttpPost("refresh_token")] public async Task> RefreshToken() { var authorizationHeader = Request.Headers["Authorization"].FirstOrDefault(); if (string.IsNullOrEmpty(authorizationHeader) || !authorizationHeader.StartsWith("Bearer ")) - { return StatusCode(HttpStatusCodes.BadRequest, new BaseResponse { - StatusCode = HttpStatusCodes.BadRequest, + StatusCode = HttpStatusCodes.BadRequest, Message = "Invalid request header format.", Data = null }); - } var oldToken = authorizationHeader.Substring("Bearer ".Length).Trim(); - + if (!_jwtService.ValidateJwtToken(oldToken)) - { return StatusCode(HttpStatusCodes.Unauthorized, new BaseResponse { - StatusCode = HttpStatusCodes.Unauthorized, - Message = "Invalid JWT token.", + StatusCode = HttpStatusCodes.Unauthorized, + Message = "Invalid JWT token.", Data = null }); - } - else + + var newToken = _jwtService.RefreshToken(oldToken); + return StatusCode(HttpStatusCodes.OK, new BaseResponse { - var newToken = _jwtService.RefreshToken(oldToken); - return StatusCode(HttpStatusCodes.OK, new BaseResponse - { - StatusCode = HttpStatusCodes.OK, - Message = "Token refreshed successfully.", - Data = new { Token = newToken } - }); - } + StatusCode = HttpStatusCodes.OK, + Message = "Token refreshed successfully.", + Data = new { Token = newToken } + }); } [HttpPost("register")] @@ -126,6 +121,20 @@ public class PatientsController : ControllerBase { var handler = new PatientProfileHandler(_patientRepository, _hashingAlgorithms); var response = await handler.HandleDelete(id).ConfigureAwait(false); + + if (response.StatusCode < HttpStatusCodes.BadRequest) DeleteMedicalHistory(id); + 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; + } + } } \ No newline at end of file diff --git a/backend/API/Middlewares/ApiKeyValidationMiddleware.cs b/backend/API/Middlewares/ApiKeyValidationMiddleware.cs index d95b3c5..a67be5d 100644 --- a/backend/API/Middlewares/ApiKeyValidationMiddleware.cs +++ b/backend/API/Middlewares/ApiKeyValidationMiddleware.cs @@ -2,15 +2,11 @@ namespace API.Middlewares; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Configuration; -using System.Threading.Tasks; - public class ApiKeyMiddleware { - private readonly RequestDelegate _next; private const string API_KEY_HEADER_NAME = "ApiKey"; private readonly string _apiKey; + private readonly RequestDelegate _next; public ApiKeyMiddleware(RequestDelegate next, IConfiguration configuration) { diff --git a/backend/API/Middlewares/JwtMiddleware.cs b/backend/API/Middlewares/JwtMiddleware.cs index ee0c2f2..6f78518 100644 --- a/backend/API/Middlewares/JwtMiddleware.cs +++ b/backend/API/Middlewares/JwtMiddleware.cs @@ -1,18 +1,14 @@ using System.Text.Json; using Application.Endpoints; +using Application.Services.Jwt; namespace API.Middlewares; -using Microsoft.AspNetCore.Http; -using System.Threading.Tasks; -using System.Linq; -using Application.Services.Jwt; - public class JwtMiddleware { - private readonly RequestDelegate _next; private readonly IJwtService _jwtService; - + private readonly RequestDelegate _next; + public JwtMiddleware(RequestDelegate next, IJwtService jwtService) { _next = next; @@ -24,7 +20,7 @@ public class JwtMiddleware var path = context.Request.Path.ToString().ToLower(); // Define the paths that should bypass JWT validation - var bypassPaths = new string[] + var bypassPaths = new[] { "/api/doctors/login", "/api/doctors/register", diff --git a/backend/API/Program.cs b/backend/API/Program.cs index 22e7d5b..2f3b9f3 100644 --- a/backend/API/Program.cs +++ b/backend/API/Program.cs @@ -1,15 +1,9 @@ -using System.Text; using API.Middlewares; using Infrastructure; using Infrastructure.Data; using Microsoft.EntityFrameworkCore; -using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi.Models; -using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.IdentityModel.Tokens; -using System.Text; - var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); diff --git a/backend/API/obj/Debug/net8.0/API.AssemblyInfo.cs b/backend/API/obj/Debug/net8.0/API.AssemblyInfo.cs index 074e0e2..bbe2bb0 100644 --- a/backend/API/obj/Debug/net8.0/API.AssemblyInfo.cs +++ b/backend/API/obj/Debug/net8.0/API.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("API")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [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.AssemblyTitleAttribute("API")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/backend/API/obj/Debug/net8.0/API.AssemblyInfoInputs.cache b/backend/API/obj/Debug/net8.0/API.AssemblyInfoInputs.cache index 5ad68cc..499558f 100644 --- a/backend/API/obj/Debug/net8.0/API.AssemblyInfoInputs.cache +++ b/backend/API/obj/Debug/net8.0/API.AssemblyInfoInputs.cache @@ -1 +1 @@ -a61f57beead854c5be97ca0cf9336ea23b19a3b596fd07a95a410574950b1887 +8e0774eef99f1b59f0ed0c9c924ec32f6e145f2aa7df39a7b5a2d83ccc6da96b diff --git a/backend/Application/Endpoints/Appointments/AppointmentManagementHandler.cs b/backend/Application/Endpoints/Appointments/AppointmentManagementHandler.cs index 2a9dc99..e528e9f 100644 --- a/backend/Application/Endpoints/Appointments/AppointmentManagementHandler.cs +++ b/backend/Application/Endpoints/Appointments/AppointmentManagementHandler.cs @@ -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; namespace Application.Endpoints.Appointments; @@ -7,8 +7,8 @@ namespace Application.Endpoints.Appointments; public class AppointmentManagementHandler { private readonly IAppointmentsMongoDbService _appointmentsMongoDbService; - private readonly IPatientRepository _patientRepository; private readonly IDoctorRepository _doctorRepository; + private readonly IPatientRepository _patientRepository; public AppointmentManagementHandler(IAppointmentsMongoDbService appointmentsMongoDbService, IPatientRepository patientRepository, IDoctorRepository doctorRepository) @@ -41,18 +41,18 @@ public class AppointmentManagementHandler var appointmentId = IdentifierGenerator.GenerateId(dto.DoctorId, dto.PatientId); var criteria = new List<(string FieldName, string Value)> { - ("_id", appointmentId), + ("_id", appointmentId) }; var appointments = await _appointmentsMongoDbService.FindAsync(criteria); - - if(!appointments.Any()) + + if (!appointments.Any()) { var appointment = new Appointment(); appointment.SetId(appointmentId); appointment.SetDoctorIid(dto.DoctorId.ToString()); appointment.SetPatientId(dto.PatientId.ToString()); appointment.AddAppointment(dto.Appointment); - + await _appointmentsMongoDbService.AddAsync(appointment); } else @@ -62,14 +62,14 @@ public class AppointmentManagementHandler await _appointmentsMongoDbService.ModifyAsync("_id", appointmentId, appointment); } - return new BaseResponse() + return new BaseResponse { StatusCode = HttpStatusCodes.Created, Message = "Appointment successfully created.", Data = null }; } - + public async Task HandleDeleteAppointment(AppointmentManagementDto dto) { var validation = new DeleteAppointmentValidator(_appointmentsMongoDbService, @@ -89,29 +89,27 @@ public class AppointmentManagementHandler Data = null }; } - + var appointmentId = IdentifierGenerator.GenerateId(dto.DoctorId, dto.PatientId); var criteria = new List<(string FieldName, string Value)> { - ("_id", appointmentId), + ("_id", appointmentId) }; var appointments = await _appointmentsMongoDbService.FindAsync(criteria); - - if(!appointments.Any()) - { - return new BaseResponse() + + if (!appointments.Any()) + return new BaseResponse { StatusCode = HttpStatusCodes.NotFound, Message = "Appointment not found in system.", Data = null }; - } - + var appointment = appointments[0]; appointment.RemoveAppointment(dto.Appointment); await _appointmentsMongoDbService.ModifyAsync("_id", appointmentId, appointment); - return new BaseResponse() + return new BaseResponse { StatusCode = HttpStatusCodes.OK, Message = "Appointment successfully removed.", diff --git a/backend/Application/Endpoints/Appointments/CreateAppointmentValidator.cs b/backend/Application/Endpoints/Appointments/CreateAppointmentValidator.cs index 4e90462..f665ab2 100644 --- a/backend/Application/Endpoints/Appointments/CreateAppointmentValidator.cs +++ b/backend/Application/Endpoints/Appointments/CreateAppointmentValidator.cs @@ -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; namespace Application.Endpoints.Appointments; @@ -9,7 +9,7 @@ public class CreateAppointmentValidator : AbstractValidator x.PatientId) .NotEmpty().WithMessage("Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString()) .MustAsync(IsPatientRegistered).WithMessage("Patient is not registered in system") @@ -30,18 +30,18 @@ public class CreateAppointmentValidator : AbstractValidator x) .MustAsync(IsAppointmentUnique).WithMessage("Appointment already in system.") .WithErrorCode(HttpStatusCodes.Conflict.ToString()); - + _appointmentsMongoDbService = appointmentsMongoDbService; _doctorRepository = doctorRepository; _patientRepository = patientRepository; } - + private async Task IsDoctorRegistered(Guid id, CancellationToken cancellationToken) { var doctor = await _doctorRepository.GetByIdAsync(id); return doctor != null; } - + private async Task IsPatientRegistered(Guid id, CancellationToken cancellationToken) { var patient = await _patientRepository.GetByIdAsync(id); @@ -50,9 +50,9 @@ public class CreateAppointmentValidator : AbstractValidator x.PatientId) .NotEmpty().WithMessage("Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString()) .MustAsync(IsPatientRegistered).WithMessage("Patient is not registered in system") @@ -31,18 +30,18 @@ public class DeleteAppointmentValidator : AbstractValidator x) .MustAsync(DoesAppointmentExists).WithMessage("Appointment not found in system") .WithErrorCode(HttpStatusCodes.NotFound.ToString()); - + _appointmentsMongoDbService = appointmentsMongoDbService; _doctorRepository = doctorRepository; _patientRepository = patientRepository; } - + private async Task IsDoctorRegistered(Guid id, CancellationToken cancellationToken) { var doctor = await _doctorRepository.GetByIdAsync(id); return doctor != null; } - + private async Task IsPatientRegistered(Guid id, CancellationToken cancellationToken) { var patient = await _patientRepository.GetByIdAsync(id); @@ -51,9 +50,9 @@ public class DeleteAppointmentValidator : AbstractValidator(); criteria.Add(("_id", chatId)); var documents = await _chatMongoDbService.FindAsync(criteria); if (!documents.Any()) - { - return new BaseResponse() + return new BaseResponse { StatusCode = HttpStatusCodes.NotFound, Message = "Access to medical history not found.", Data = null }; - } var chat = documents[0].Messages; chat.Add(new Message(sendMessageDto.Sender, sendMessageDto.Message)); @@ -71,7 +67,7 @@ public class ChatHandler newChat.SetMessages(chat); await _chatMongoDbService.ModifyAsync("_id", chatId, newChat); - + return new BaseResponse { StatusCode = HttpStatusCodes.NoContent, @@ -100,20 +96,18 @@ public class ChatHandler } if (!await CheckForUsersExistence(getConversationDto.IdUser1, getConversationDto.IdUser2)) - { return new BaseResponse { StatusCode = HttpStatusCodes.BadRequest, Message = "Users can't be found in the system.", Data = null }; - } var chatId = IdentifierGenerator.GenerateId(getConversationDto.IdUser1, getConversationDto.IdUser2); - + var criteria = new List<(string, string)>(); criteria.Add(("_id", chatId)); - + Chat? chat = null; var documents = await _chatMongoDbService.FindAsync(criteria); @@ -128,7 +122,7 @@ public class ChatHandler { chat = documents[0]; } - + return new BaseResponse { StatusCode = HttpStatusCodes.OK, @@ -141,7 +135,7 @@ public class ChatHandler { var firstCheck = await _patientRepository.GetByIdAsync(idUser1) != null && await _doctorRepository.GetByIdAsync(idUser2) != null; - + var secondCheck = await _patientRepository.GetByIdAsync(idUser2) != null && await _doctorRepository.GetByIdAsync(idUser1) != null; diff --git a/backend/Application/Endpoints/Chats/SendMessageValidator.cs b/backend/Application/Endpoints/Chats/SendMessageValidator.cs index fc6aa4d..3b0731b 100644 --- a/backend/Application/Endpoints/Chats/SendMessageValidator.cs +++ b/backend/Application/Endpoints/Chats/SendMessageValidator.cs @@ -11,7 +11,7 @@ public class SendMessageValidator : AbstractValidator RuleFor(x => x.Receiver) .NotEmpty().WithMessage("Receiver Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString()); - + RuleFor(x => x.Message) .NotEmpty().WithMessage("Message is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString()); } diff --git a/backend/Application/Endpoints/Doctors/Login/DoctorLoginHandler.cs b/backend/Application/Endpoints/Doctors/Login/DoctorLoginHandler.cs index 8fa87ec..06989d7 100644 --- a/backend/Application/Endpoints/Doctors/Login/DoctorLoginHandler.cs +++ b/backend/Application/Endpoints/Doctors/Login/DoctorLoginHandler.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using Application.Services.HashingAlgorithms; namespace Application.Endpoints.Doctors.Login; diff --git a/backend/Application/Endpoints/Doctors/Login/DoctorLoginValidation.cs b/backend/Application/Endpoints/Doctors/Login/DoctorLoginValidation.cs index b7abda5..7e545eb 100644 --- a/backend/Application/Endpoints/Doctors/Login/DoctorLoginValidation.cs +++ b/backend/Application/Endpoints/Doctors/Login/DoctorLoginValidation.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using FluentValidation; namespace Application.Endpoints.Doctors.Login; diff --git a/backend/Application/Endpoints/Doctors/Profile/DoctorProfileHandler.cs b/backend/Application/Endpoints/Doctors/Profile/DoctorProfileHandler.cs index 7dfe33e..890294d 100644 --- a/backend/Application/Endpoints/Doctors/Profile/DoctorProfileHandler.cs +++ b/backend/Application/Endpoints/Doctors/Profile/DoctorProfileHandler.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using Application.Services.HashingAlgorithms; namespace Application.Endpoints.Doctors.Profile; diff --git a/backend/Application/Endpoints/Doctors/Profile/DoctorProfileValidation.cs b/backend/Application/Endpoints/Doctors/Profile/DoctorProfileValidation.cs index b9f09b8..78461e0 100644 --- a/backend/Application/Endpoints/Doctors/Profile/DoctorProfileValidation.cs +++ b/backend/Application/Endpoints/Doctors/Profile/DoctorProfileValidation.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using FluentValidation; namespace Application.Endpoints.Doctors.Profile; diff --git a/backend/Application/Endpoints/Doctors/Registration/DoctorRegistrationHandler.cs b/backend/Application/Endpoints/Doctors/Registration/DoctorRegistrationHandler.cs index 270a96f..a547fd1 100644 --- a/backend/Application/Endpoints/Doctors/Registration/DoctorRegistrationHandler.cs +++ b/backend/Application/Endpoints/Doctors/Registration/DoctorRegistrationHandler.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using Application.Services.HashingAlgorithms; using Core.Entities; diff --git a/backend/Application/Endpoints/Doctors/Registration/DoctorRegistrationValidation.cs b/backend/Application/Endpoints/Doctors/Registration/DoctorRegistrationValidation.cs index e753296..4da484b 100644 --- a/backend/Application/Endpoints/Doctors/Registration/DoctorRegistrationValidation.cs +++ b/backend/Application/Endpoints/Doctors/Registration/DoctorRegistrationValidation.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using FluentValidation; namespace Application.Endpoints.Doctors.Registration; diff --git a/backend/Application/Endpoints/Doctors/ResetPassword/DoctorResetPasswordHandler.cs b/backend/Application/Endpoints/Doctors/ResetPassword/DoctorResetPasswordHandler.cs index 6597da3..2ce1d5d 100644 --- a/backend/Application/Endpoints/Doctors/ResetPassword/DoctorResetPasswordHandler.cs +++ b/backend/Application/Endpoints/Doctors/ResetPassword/DoctorResetPasswordHandler.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using Application.Services.HashingAlgorithms; namespace Application.Endpoints.Doctors.ResetPassword; diff --git a/backend/Application/Endpoints/Doctors/ResetPassword/DoctorResetPasswordValidation.cs b/backend/Application/Endpoints/Doctors/ResetPassword/DoctorResetPasswordValidation.cs index c1b9f90..0c1a12f 100644 --- a/backend/Application/Endpoints/Doctors/ResetPassword/DoctorResetPasswordValidation.cs +++ b/backend/Application/Endpoints/Doctors/ResetPassword/DoctorResetPasswordValidation.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using FluentValidation; namespace Application.Endpoints.Doctors.ResetPassword; diff --git a/backend/Application/Endpoints/IdentifierGenerator.cs b/backend/Application/Endpoints/IdentifierGenerator.cs index 6a0f500..4f18b9d 100644 --- a/backend/Application/Endpoints/IdentifierGenerator.cs +++ b/backend/Application/Endpoints/IdentifierGenerator.cs @@ -5,12 +5,12 @@ public class IdentifierGenerator public static string GenerateId(Guid id1, Guid id2) { // Convert GUIDs to strings - string strId1 = id1.ToString(); - string strId2 = id2.ToString(); + var strId1 = id1.ToString(); + var strId2 = id2.ToString(); // Sort the GUID strings - string firstId = strId1.CompareTo(strId2) < 0 ? strId1 : strId2; - string secondId = strId1.CompareTo(strId2) < 0 ? strId2 : strId1; + var firstId = strId1.CompareTo(strId2) < 0 ? strId1 : strId2; + var secondId = strId1.CompareTo(strId2) < 0 ? strId2 : strId1; // Combine them to get a symmetric string return firstId + "-" + secondId; diff --git a/backend/Application/Endpoints/MedicalHistories/FileManagement/MedicalHistoryCreateValidation.cs b/backend/Application/Endpoints/MedicalHistories/FileManagement/MedicalHistoryCreateValidation.cs index 30c7eb3..b96f32f 100644 --- a/backend/Application/Endpoints/MedicalHistories/FileManagement/MedicalHistoryCreateValidation.cs +++ b/backend/Application/Endpoints/MedicalHistories/FileManagement/MedicalHistoryCreateValidation.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using FluentValidation; namespace Application.Endpoints.MedicalHistories.FileManagement; diff --git a/backend/Application/Endpoints/MedicalHistories/FileManagement/MedicalHistoryFileManagementHandler.cs b/backend/Application/Endpoints/MedicalHistories/FileManagement/MedicalHistoryFileManagementHandler.cs index 974df35..5d93b60 100644 --- a/backend/Application/Endpoints/MedicalHistories/FileManagement/MedicalHistoryFileManagementHandler.cs +++ b/backend/Application/Endpoints/MedicalHistories/FileManagement/MedicalHistoryFileManagementHandler.cs @@ -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; namespace Application.Endpoints.MedicalHistories.FileManagement; public class MedicalHistoryFileManagementHandler { - private readonly IMedicalHistoryRepository _medicalHistoryRepository; private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService; + private readonly IMedicalHistoryRepository _medicalHistoryRepository; private readonly IPatientRepository _patientRepository; public MedicalHistoryFileManagementHandler(IMedicalHistoryRepository medicalHistoryRepository, diff --git a/backend/Application/Endpoints/MedicalHistories/FileManagement/MedicalHistoryUpdateValidation.cs b/backend/Application/Endpoints/MedicalHistories/FileManagement/MedicalHistoryUpdateValidation.cs index 73a9368..f200470 100644 --- a/backend/Application/Endpoints/MedicalHistories/FileManagement/MedicalHistoryUpdateValidation.cs +++ b/backend/Application/Endpoints/MedicalHistories/FileManagement/MedicalHistoryUpdateValidation.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using FluentValidation; namespace Application.Endpoints.MedicalHistories.FileManagement; diff --git a/backend/Application/Endpoints/MedicalHistories/ManageAuthorization/MedicalHistoryManageAuthorizationHandler.cs b/backend/Application/Endpoints/MedicalHistories/ManageAuthorization/MedicalHistoryManageAuthorizationHandler.cs index d92e786..18916b2 100644 --- a/backend/Application/Endpoints/MedicalHistories/ManageAuthorization/MedicalHistoryManageAuthorizationHandler.cs +++ b/backend/Application/Endpoints/MedicalHistories/ManageAuthorization/MedicalHistoryManageAuthorizationHandler.cs @@ -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; public class MedicalHistoryManageAuthorizationHandler { - private readonly IMedicalHistoryRepository _medicalHistoryRepository; private readonly IDoctorRepository _doctorRepository; private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService; + private readonly IMedicalHistoryRepository _medicalHistoryRepository; public MedicalHistoryManageAuthorizationHandler(IMedicalHistoryRepository medicalHistoryRepository, IMedicalHistoryMongoDbService medicalHistoryMongoDbService, IDoctorRepository doctorRepository) @@ -41,28 +41,24 @@ public class MedicalHistoryManageAuthorizationHandler var documents = await _medicalHistoryMongoDbService.FindAsync(criteria); if (!documents.Any()) - { - return new BaseResponse() + return new BaseResponse { StatusCode = HttpStatusCodes.NotFound, Message = "Access to medical history not found.", Data = null }; - } - + var authorisations = documents[0].Authorisation; if (authorisations.Contains(infoDto.ToString())) - { - return new BaseResponse() + return new BaseResponse { StatusCode = HttpStatusCodes.Conflict, Message = "Access to medical history already granted.", Data = null }; - } - + authorisations.Add(infoDto.DoctorId.ToString()); - var authorizationModel = new MedicalHistoryAuthorisationModel() + var authorizationModel = new MedicalHistoryAuthorisationModel { Id = infoDto.MedicalRecordId.ToString(), Authorisation = authorisations @@ -70,7 +66,7 @@ public class MedicalHistoryManageAuthorizationHandler await _medicalHistoryMongoDbService.ModifyAsync("_id", infoDto.MedicalRecordId.ToString(), authorizationModel); - return new BaseResponse() + return new BaseResponse { StatusCode = HttpStatusCodes.OK, Message = "Access to medical history granted.", @@ -102,28 +98,24 @@ public class MedicalHistoryManageAuthorizationHandler var documents = await _medicalHistoryMongoDbService.FindAsync(criteria); if (!documents.Any()) - { - return new BaseResponse() + return new BaseResponse { StatusCode = HttpStatusCodes.NotFound, Message = "Access to medical history not found.", Data = null }; - } - + var authorisations = documents[0].Authorisation; if (!authorisations.Contains(infoDto.DoctorId.ToString())) - { - return new BaseResponse() + return new BaseResponse { StatusCode = HttpStatusCodes.Conflict, Message = "Access to medical history already revoked.", Data = null }; - } - + authorisations.Remove(infoDto.DoctorId.ToString()); - var authorizationModel = new MedicalHistoryAuthorisationModel() + var authorizationModel = new MedicalHistoryAuthorisationModel { Id = infoDto.MedicalRecordId.ToString(), Authorisation = authorisations @@ -131,7 +123,7 @@ public class MedicalHistoryManageAuthorizationHandler await _medicalHistoryMongoDbService.ModifyAsync("_id", infoDto.MedicalRecordId.ToString(), authorizationModel); - return new BaseResponse() + return new BaseResponse { StatusCode = HttpStatusCodes.OK, Message = "Access to medical history granted.", diff --git a/backend/Application/Endpoints/MedicalHistories/ManageAuthorization/MedicalHistoryManageAuthorizationValidation.cs b/backend/Application/Endpoints/MedicalHistories/ManageAuthorization/MedicalHistoryManageAuthorizationValidation.cs index a4fa93a..201027a 100644 --- a/backend/Application/Endpoints/MedicalHistories/ManageAuthorization/MedicalHistoryManageAuthorizationValidation.cs +++ b/backend/Application/Endpoints/MedicalHistories/ManageAuthorization/MedicalHistoryManageAuthorizationValidation.cs @@ -1,12 +1,12 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using FluentValidation; namespace Application.Endpoints.MedicalHistories.ManageAuthorization; public class MedicalHistoryManageAuthorizationValidation : AbstractValidator { - private readonly IMedicalHistoryRepository _medicalHistoryRepository; private readonly IDoctorRepository _doctorRepository; + private readonly IMedicalHistoryRepository _medicalHistoryRepository; public MedicalHistoryManageAuthorizationValidation(IMedicalHistoryRepository medicalHistoryRepository, IDoctorRepository doctorRepository) diff --git a/backend/Application/Endpoints/MedicalHistories/MedicalHistoryAuthorisationModel.cs b/backend/Application/Endpoints/MedicalHistories/MedicalHistoryAuthorisationModel.cs index 32f2c67..d60e8a3 100644 --- a/backend/Application/Endpoints/MedicalHistories/MedicalHistoryAuthorisationModel.cs +++ b/backend/Application/Endpoints/MedicalHistories/MedicalHistoryAuthorisationModel.cs @@ -3,5 +3,5 @@ public class MedicalHistoryAuthorisationModel { public string Id { get; set; } - public List Authorisation { get; set; } = new List(); + public List Authorisation { get; set; } = new(); } \ No newline at end of file diff --git a/backend/Application/Endpoints/MedicalHistories/MedicalHistoryCreateValidation.cs b/backend/Application/Endpoints/MedicalHistories/MedicalHistoryCreateValidation.cs index 7179d5c..73a15e6 100644 --- a/backend/Application/Endpoints/MedicalHistories/MedicalHistoryCreateValidation.cs +++ b/backend/Application/Endpoints/MedicalHistories/MedicalHistoryCreateValidation.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using FluentValidation; namespace Application.Endpoints.MedicalHistories; diff --git a/backend/Application/Endpoints/MedicalHistories/MedicalHistoryHandler.cs b/backend/Application/Endpoints/MedicalHistories/MedicalHistoryHandler.cs index 0edc3ec..cf05d39 100644 --- a/backend/Application/Endpoints/MedicalHistories/MedicalHistoryHandler.cs +++ b/backend/Application/Endpoints/MedicalHistories/MedicalHistoryHandler.cs @@ -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; namespace Application.Endpoints.MedicalHistories; public class MedicalHistoryHandler { - private readonly IMedicalHistoryRepository _medicalHistoryRepository; private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService; + private readonly IMedicalHistoryRepository _medicalHistoryRepository; private readonly IPatientRepository _patientRepository; public MedicalHistoryHandler(IMedicalHistoryRepository medicalHistoryRepository, @@ -80,7 +80,7 @@ public class MedicalHistoryHandler UserId = medicalHistoryCreateDto.UserId, Content = medicalHistoryCreateDto.Content }; - + var medicalHistoryId = medicalHistory.Id; var newMedicalHistory = new MedicalHistoryAuthorisationModel { diff --git a/backend/Application/Endpoints/MedicalHistories/MedicalHistoryUpdateValidation.cs b/backend/Application/Endpoints/MedicalHistories/MedicalHistoryUpdateValidation.cs index b9993c9..bb5b691 100644 --- a/backend/Application/Endpoints/MedicalHistories/MedicalHistoryUpdateValidation.cs +++ b/backend/Application/Endpoints/MedicalHistories/MedicalHistoryUpdateValidation.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using FluentValidation; namespace Application.Endpoints.MedicalHistories; diff --git a/backend/Application/Endpoints/Patients/Login/PatientLoginHandler.cs b/backend/Application/Endpoints/Patients/Login/PatientLoginHandler.cs index 8127a19..32a6c21 100644 --- a/backend/Application/Endpoints/Patients/Login/PatientLoginHandler.cs +++ b/backend/Application/Endpoints/Patients/Login/PatientLoginHandler.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; namespace Application.Endpoints.Patients.Login; diff --git a/backend/Application/Endpoints/Patients/Login/PatientLoginValidation.cs b/backend/Application/Endpoints/Patients/Login/PatientLoginValidation.cs index 21ff7b3..20e8ad9 100644 --- a/backend/Application/Endpoints/Patients/Login/PatientLoginValidation.cs +++ b/backend/Application/Endpoints/Patients/Login/PatientLoginValidation.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using FluentValidation; namespace Application.Endpoints.Patients.Login; diff --git a/backend/Application/Endpoints/Patients/Profile/PatientProfileHandler.cs b/backend/Application/Endpoints/Patients/Profile/PatientProfileHandler.cs index db0d106..a140d76 100644 --- a/backend/Application/Endpoints/Patients/Profile/PatientProfileHandler.cs +++ b/backend/Application/Endpoints/Patients/Profile/PatientProfileHandler.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using Application.Services.HashingAlgorithms; namespace Application.Endpoints.Patients.Profile; diff --git a/backend/Application/Endpoints/Patients/Profile/PatientProfileValidation.cs b/backend/Application/Endpoints/Patients/Profile/PatientProfileValidation.cs index 00b73c4..9116275 100644 --- a/backend/Application/Endpoints/Patients/Profile/PatientProfileValidation.cs +++ b/backend/Application/Endpoints/Patients/Profile/PatientProfileValidation.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using FluentValidation; namespace Application.Endpoints.Patients.Profile; diff --git a/backend/Application/Endpoints/Patients/Registration/PatientRegistrationHandler.cs b/backend/Application/Endpoints/Patients/Registration/PatientRegistrationHandler.cs index 84388d9..ad9374c 100644 --- a/backend/Application/Endpoints/Patients/Registration/PatientRegistrationHandler.cs +++ b/backend/Application/Endpoints/Patients/Registration/PatientRegistrationHandler.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using Application.Services.HashingAlgorithms; using Core.Entities; diff --git a/backend/Application/Endpoints/Patients/Registration/PatientRegistrationValidation.cs b/backend/Application/Endpoints/Patients/Registration/PatientRegistrationValidation.cs index f05ce5c..7458394 100644 --- a/backend/Application/Endpoints/Patients/Registration/PatientRegistrationValidation.cs +++ b/backend/Application/Endpoints/Patients/Registration/PatientRegistrationValidation.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using FluentValidation; namespace Application.Endpoints.Patients.Registration; diff --git a/backend/Application/Endpoints/Patients/ResetPassword/PatientResetPasswordHandler.cs b/backend/Application/Endpoints/Patients/ResetPassword/PatientResetPasswordHandler.cs index 2df47b5..6073754 100644 --- a/backend/Application/Endpoints/Patients/ResetPassword/PatientResetPasswordHandler.cs +++ b/backend/Application/Endpoints/Patients/ResetPassword/PatientResetPasswordHandler.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using Application.Services.HashingAlgorithms; namespace Application.Endpoints.Patients.ResetPassword; diff --git a/backend/Application/Endpoints/Patients/ResetPassword/PatientResetPasswordValidation.cs b/backend/Application/Endpoints/Patients/ResetPassword/PatientResetPasswordValidation.cs index 42f18b4..ecc037f 100644 --- a/backend/Application/Endpoints/Patients/ResetPassword/PatientResetPasswordValidation.cs +++ b/backend/Application/Endpoints/Patients/ResetPassword/PatientResetPasswordValidation.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using FluentValidation; namespace Application.Endpoints.Patients.ResetPassword; diff --git a/backend/Application/Services/Database/MongoDB/IAppointmentsHistoryMongoDbService.cs b/backend/Application/Services/Database/MongoDB/IAppointmentsHistoryMongoDbService.cs index c501266..467b9a5 100644 --- a/backend/Application/Services/Database/MongoDB/IAppointmentsHistoryMongoDbService.cs +++ b/backend/Application/Services/Database/MongoDB/IAppointmentsHistoryMongoDbService.cs @@ -14,7 +14,7 @@ public interface IAppointmentsMongoDbService Task ModifyAsync(string keyField, string keyValue, T document); Task DeleteAsync(string keyField, string keyValue); - + Task DeleteByIdAsync(string id); public Task IsAppointmentUnique(AppointmentManagementDto dto); diff --git a/backend/Application/Services/Database/MongoDB/IChatHistoryMongoDbService.cs b/backend/Application/Services/Database/MongoDB/IChatHistoryMongoDbService.cs index 6da1a0b..be3dd78 100644 --- a/backend/Application/Services/Database/MongoDB/IChatHistoryMongoDbService.cs +++ b/backend/Application/Services/Database/MongoDB/IChatHistoryMongoDbService.cs @@ -13,6 +13,6 @@ public interface IChatMongoDbService Task ModifyAsync(string keyField, string keyValue, T document); Task DeleteAsync(string keyField, string keyValue); - + Task DeleteByIdAsync(string id); } \ No newline at end of file diff --git a/backend/Application/Services/Database/MongoDB/IMedicalHistoryMongoDbService.cs b/backend/Application/Services/Database/MongoDB/IMedicalHistoryMongoDbService.cs index 0b71a2a..d02d92f 100644 --- a/backend/Application/Services/Database/MongoDB/IMedicalHistoryMongoDbService.cs +++ b/backend/Application/Services/Database/MongoDB/IMedicalHistoryMongoDbService.cs @@ -1,5 +1,4 @@ -using Application.Endpoints.MedicalHistories; -using MongoDB.Driver; +using MongoDB.Driver; namespace Application.Services.Database.MongoDB; @@ -14,6 +13,6 @@ public interface IMedicalHistoryMongoDbService Task ModifyAsync(string keyField, string keyValue, T document); Task DeleteAsync(string keyField, string keyValue); - + Task DeleteByIdAsync(string id); } \ No newline at end of file diff --git a/backend/Application/Services/Database/PostgreSQL/IConversation.cs b/backend/Application/Services/Database/PostgreSQL/IConversation.cs deleted file mode 100644 index 75e498c..0000000 --- a/backend/Application/Services/Database/PostgreSQL/IConversation.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace Application.Services.Database; - -public interface IConversationRepository -{ -} \ No newline at end of file diff --git a/backend/Application/Services/Database/PostgreSQL/IDoctors.cs b/backend/Application/Services/Database/PostgreSQL/IDoctors.cs index 2eef847..8de5550 100644 --- a/backend/Application/Services/Database/PostgreSQL/IDoctors.cs +++ b/backend/Application/Services/Database/PostgreSQL/IDoctors.cs @@ -1,6 +1,6 @@ using Core.Entities; -namespace Application.Services.Database; +namespace Application.Services.Database.PostgreSQL; public interface IDoctorRepository { diff --git a/backend/Application/Services/Database/PostgreSQL/IMedicalHistory.cs b/backend/Application/Services/Database/PostgreSQL/IMedicalHistory.cs index f7f01c8..bf188cf 100644 --- a/backend/Application/Services/Database/PostgreSQL/IMedicalHistory.cs +++ b/backend/Application/Services/Database/PostgreSQL/IMedicalHistory.cs @@ -1,6 +1,6 @@ using Core.Entities; -namespace Application.Services.Database; +namespace Application.Services.Database.PostgreSQL; public interface IMedicalHistoryRepository { diff --git a/backend/Application/Services/Database/PostgreSQL/IPatients.cs b/backend/Application/Services/Database/PostgreSQL/IPatients.cs index 29a6581..f477726 100644 --- a/backend/Application/Services/Database/PostgreSQL/IPatients.cs +++ b/backend/Application/Services/Database/PostgreSQL/IPatients.cs @@ -1,6 +1,6 @@ using Core.Entities; -namespace Application.Services.Database; +namespace Application.Services.Database.PostgreSQL; public interface IPatientRepository { @@ -10,9 +10,9 @@ public interface IPatientRepository Task FindByEmailAsync(string email); - Task UpdateAsync(Patient doctor); + Task UpdateAsync(Patient patient); - Task DeleteAsync(Patient doctor); + Task DeleteAsync(Patient patient); Task> GetAllAsync(); } \ No newline at end of file diff --git a/backend/Application/Services/Jwt/IJwtService.cs b/backend/Application/Services/Jwt/IJwtService.cs index 9750de1..a9b5798 100644 --- a/backend/Application/Services/Jwt/IJwtService.cs +++ b/backend/Application/Services/Jwt/IJwtService.cs @@ -1,6 +1,4 @@ -using System.Security.Claims; - -namespace Application.Services.Jwt; +namespace Application.Services.Jwt; public interface IJwtService { diff --git a/backend/Core/Entities/Appointment.cs b/backend/Core/Entities/Appointment.cs index 2a98608..5935351 100644 --- a/backend/Core/Entities/Appointment.cs +++ b/backend/Core/Entities/Appointment.cs @@ -6,25 +6,38 @@ public class Appointment { AppointmentsList = new List(); } - + public string Id { get; private set; } public string PatientId { get; private set; } public string DoctorId { get; private set; } - public List AppointmentsList { get; private set; } + public List 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) { - 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); } 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); } } \ No newline at end of file diff --git a/backend/Core/Entities/Chat.cs b/backend/Core/Entities/Chat.cs index 88989f2..9230d3f 100644 --- a/backend/Core/Entities/Chat.cs +++ b/backend/Core/Entities/Chat.cs @@ -8,8 +8,15 @@ public class Chat public string Id { get; private set; } public List Messages { get; private set; } = new(); - public void SetId(string id) { Id = id; } - public void SetMessages(List messages) { Messages = messages; } + public void SetId(string id) + { + Id = id; + } + + public void SetMessages(List messages) + { + Messages = messages; + } } public class Message @@ -19,12 +26,18 @@ public class Message UserId = userId; Content = content; } - - [BsonRepresentation(BsonType.String)] - public Guid UserId { get; private set; } + + [BsonRepresentation(BsonType.String)] public Guid UserId { get; private set; } public string Content { get; private set; } - public void SetUserId(Guid userId) { UserId = userId; } - public void SetContent(string content) { Content = content; } + public void SetUserId(Guid userId) + { + UserId = userId; + } + + public void SetContent(string content) + { + Content = content; + } } \ No newline at end of file diff --git a/backend/Infrastructure/Infrastructure.csproj b/backend/Infrastructure/Infrastructure.csproj index 9d82a19..fc09211 100644 --- a/backend/Infrastructure/Infrastructure.csproj +++ b/backend/Infrastructure/Infrastructure.csproj @@ -16,10 +16,10 @@ - + - + diff --git a/backend/Infrastructure/InfrastructureDI.cs b/backend/Infrastructure/InfrastructureDI.cs index 7770b92..15cdb0c 100644 --- a/backend/Infrastructure/InfrastructureDI.cs +++ b/backend/Infrastructure/InfrastructureDI.cs @@ -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.Jwt; - using Infrastructure.Data; using Infrastructure.Services.HashingAlgorithms; using Infrastructure.Services.MongoDB; using Infrastructure.Services.PostgreSQL; - using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using MongoDB.Driver; namespace Infrastructure; @@ -38,7 +35,7 @@ public static class DependencyInjection return new MedicalHistoryMongoDbService(connectionString, databaseName, collectionName); }); - + services.AddSingleton(serviceProvider => { var configuration = serviceProvider.GetRequiredService(); @@ -48,7 +45,7 @@ public static class DependencyInjection return new ChatMongoDbService(connectionString, databaseName, collectionName); }); - + services.AddSingleton(serviceProvider => { var configuration = serviceProvider.GetRequiredService(); @@ -58,19 +55,18 @@ public static class DependencyInjection return new AppointmentsMongoDbService(connectionString, databaseName, collectionName); }); - + // Other Services services.AddScoped(); - + services.AddSingleton(serviceProvider => { var configuration = serviceProvider.GetRequiredService(); return new JwtService(configuration); }); - + // services.AddScoped(); return services; } - } \ No newline at end of file diff --git a/backend/Infrastructure/Services/Jwt/JWTService.cs b/backend/Infrastructure/Services/Jwt/JWTService.cs index 40c742c..04b2b51 100644 --- a/backend/Infrastructure/Services/Jwt/JWTService.cs +++ b/backend/Infrastructure/Services/Jwt/JWTService.cs @@ -1,17 +1,16 @@ -using Microsoft.Extensions.Configuration; -using Microsoft.IdentityModel.Tokens; -using System; -using System.IdentityModel.Tokens.Jwt; +using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; using Application.Services.Jwt; +using Microsoft.Extensions.Configuration; +using Microsoft.IdentityModel.Tokens; public class JwtService : IJwtService { - private readonly string _secretKey; - private readonly string _issuer; private readonly string _audience; private readonly double _expiryMinutes; + private readonly string _issuer; + private readonly string _secretKey; public JwtService(IConfiguration configuration) { @@ -34,13 +33,14 @@ public class JwtService : IJwtService Expires = DateTime.UtcNow.AddMinutes(_expiryMinutes), Issuer = _issuer, Audience = _audience, - SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) + SigningCredentials = + new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); return tokenHandler.WriteToken(token); } - + public bool ValidateJwtToken(string token) { if (string.IsNullOrWhiteSpace(token)) @@ -58,9 +58,9 @@ public class JwtService : IJwtService ValidateAudience = true, ValidIssuer = _issuer, ValidAudience = _audience, - ClockSkew = TimeSpan.Zero, - }, out SecurityToken validatedToken); - + ClockSkew = TimeSpan.Zero + }, out var validatedToken); + return true; } catch @@ -68,20 +68,14 @@ public class JwtService : IJwtService return false; } } - + public string RefreshToken(string token) { var principal = ValidateTokenAndGetPrincipal(token); - if (principal == null) - { - throw new SecurityTokenException("Invalid token."); - } + if (principal == null) throw new SecurityTokenException("Invalid token."); var emailClaim = principal.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email); - if (emailClaim == null) - { - throw new SecurityTokenException("Token does not contain an email claim."); - } + if (emailClaim == null) throw new SecurityTokenException("Token does not contain an email claim."); return GenerateJwtToken(emailClaim.Value); } @@ -100,7 +94,7 @@ public class JwtService : IJwtService ValidateAudience = true, ValidIssuer = _issuer, ValidAudience = _audience, - ClockSkew = TimeSpan.Zero, + ClockSkew = TimeSpan.Zero }, out _); return principal; @@ -111,5 +105,4 @@ public class JwtService : IJwtService return null; } } - } \ No newline at end of file diff --git a/backend/Infrastructure/Services/MongoDB/AppointmentsMongoDbService.cs b/backend/Infrastructure/Services/MongoDB/AppointmentsMongoDbService.cs index 79087dc..f80c288 100644 --- a/backend/Infrastructure/Services/MongoDB/AppointmentsMongoDbService.cs +++ b/backend/Infrastructure/Services/MongoDB/AppointmentsMongoDbService.cs @@ -14,46 +14,38 @@ public class AppointmentsMongoDbService : MongoDbService, IAppointmentsMongoDbSe public async Task IsAppointmentUnique(AppointmentManagementDto dto) { var appointment = dto.Appointment.ToUniversalTime(); - + var criteria = new List<(string FieldName, string Value)> { ("DoctorId", dto.DoctorId.ToString()), ("PatientId", dto.PatientId.ToString()) }; - + var appointments = await FindAsync(criteria); foreach (var app in appointments) - { if (app.AppointmentsList.Any(a => a.Date == appointment.Date)) - { return false; - } - } - + return true; } public async Task DoesAppointmentExists(AppointmentManagementDto dto) { var appointment = dto.Appointment.ToUniversalTime(); - + var criteria = new List<(string FieldName, string Value)> { ("DoctorId", dto.DoctorId.ToString()), ("PatientId", dto.PatientId.ToString()) }; - + var appointments = await FindAsync(criteria); foreach (var app in appointments) - { if (app.AppointmentsList.Any(a => a.Date == appointment.Date)) - { return true; - } - } - + return false; } } \ No newline at end of file diff --git a/backend/Infrastructure/Services/MongoDB/MongoDBServices.cs b/backend/Infrastructure/Services/MongoDB/MongoDBServices.cs index 99c8fef..03db3f8 100644 --- a/backend/Infrastructure/Services/MongoDB/MongoDBServices.cs +++ b/backend/Infrastructure/Services/MongoDB/MongoDBServices.cs @@ -1,81 +1,79 @@ -using Application.Services.Database; +using MongoDB.Bson; 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; - private readonly string _databaseName; - private readonly string _collectionName; + _databaseName = databaseName; + _collectionName = 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; - _collectionName = 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 - { - var result = _database.GetDatabase("admin").RunCommand(new BsonDocument("ping", 1)); - Console.WriteLine("Pinged your deployment. You successfully connected to MongoDB!"); - } - catch (Exception ex) - { - Console.WriteLine(ex); - } + var result = _database.GetDatabase("admin").RunCommand(new BsonDocument("ping", 1)); + Console.WriteLine("Pinged your deployment. You successfully connected to MongoDB!"); } - - public IMongoCollection GetCollection() + catch (Exception ex) { - return _database.GetDatabase(_databaseName).GetCollection(_collectionName); - } - - public async Task> FindAsync(List<(string FieldName, string Value)> criteria) - { - var collection = _database.GetDatabase(_databaseName).GetCollection(_collectionName); - - var filters = new List>(); - foreach (var (FieldName, Value) in criteria) filters.Add(Builders.Filter.Eq(FieldName, Value)); - - var combinedFilter = Builders.Filter.And(filters); - - return await collection.Find(combinedFilter).ToListAsync(); - } - - public async Task AddAsync(T document) - { - var collection = _database.GetDatabase(_databaseName).GetCollection(_collectionName); - await collection.InsertOneAsync(document); - } - - public async Task ModifyAsync(string keyField, string keyValue, T document) - { - var collection = _database.GetDatabase(_databaseName).GetCollection(_collectionName); - var filter = Builders.Filter.Eq(keyField, keyValue); - await collection.ReplaceOneAsync(filter, document, new ReplaceOptions { IsUpsert = true }); - } - - public async Task DeleteAsync(string keyField, string keyValue) - { - var collection = _database.GetDatabase(_databaseName).GetCollection(_collectionName); - var filter = Builders.Filter.Eq(keyField, keyValue); - await collection.DeleteOneAsync(filter); - } - - public async Task DeleteByIdAsync(string id) - { - var collection = _database.GetDatabase(_databaseName).GetCollection(_collectionName); - var filter = Builders.Filter.Eq("_id", id); - await collection.DeleteOneAsync(filter); + Console.WriteLine(ex); } } + + public IMongoCollection GetCollection() + { + return _database.GetDatabase(_databaseName).GetCollection(_collectionName); + } + + public async Task> FindAsync(List<(string FieldName, string Value)> criteria) + { + var collection = _database.GetDatabase(_databaseName).GetCollection(_collectionName); + + var filters = new List>(); + foreach (var (FieldName, Value) in criteria) filters.Add(Builders.Filter.Eq(FieldName, Value)); + + var combinedFilter = Builders.Filter.And(filters); + + return await collection.Find(combinedFilter).ToListAsync(); + } + + public async Task AddAsync(T document) + { + var collection = _database.GetDatabase(_databaseName).GetCollection(_collectionName); + await collection.InsertOneAsync(document); + } + + public async Task ModifyAsync(string keyField, string keyValue, T document) + { + var collection = _database.GetDatabase(_databaseName).GetCollection(_collectionName); + var filter = Builders.Filter.Eq(keyField, keyValue); + await collection.ReplaceOneAsync(filter, document, new ReplaceOptions { IsUpsert = true }); + } + + public async Task DeleteAsync(string keyField, string keyValue) + { + var collection = _database.GetDatabase(_databaseName).GetCollection(_collectionName); + var filter = Builders.Filter.Eq(keyField, keyValue); + await collection.DeleteOneAsync(filter); + } + + public async Task DeleteByIdAsync(string id) + { + var collection = _database.GetDatabase(_databaseName).GetCollection(_collectionName); + var filter = Builders.Filter.Eq("_id", id); + await collection.DeleteOneAsync(filter); + } } \ No newline at end of file diff --git a/backend/Infrastructure/Services/PostgreSQL/DoctorRepository.cs b/backend/Infrastructure/Services/PostgreSQL/DoctorRepository.cs index 7ae8122..4228259 100644 --- a/backend/Infrastructure/Services/PostgreSQL/DoctorRepository.cs +++ b/backend/Infrastructure/Services/PostgreSQL/DoctorRepository.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using Core.Entities; using Infrastructure.Data; using Microsoft.EntityFrameworkCore; diff --git a/backend/Infrastructure/Services/PostgreSQL/MedicalHistoryRepository.cs b/backend/Infrastructure/Services/PostgreSQL/MedicalHistoryRepository.cs index 644e64a..f4e0455 100644 --- a/backend/Infrastructure/Services/PostgreSQL/MedicalHistoryRepository.cs +++ b/backend/Infrastructure/Services/PostgreSQL/MedicalHistoryRepository.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using Core.Entities; using Infrastructure.Data; using Microsoft.EntityFrameworkCore; diff --git a/backend/Infrastructure/Services/PostgreSQL/PatientRepository.cs b/backend/Infrastructure/Services/PostgreSQL/PatientRepository.cs index 5b606ca..97588c1 100644 --- a/backend/Infrastructure/Services/PostgreSQL/PatientRepository.cs +++ b/backend/Infrastructure/Services/PostgreSQL/PatientRepository.cs @@ -1,4 +1,4 @@ -using Application.Services.Database; +using Application.Services.Database.PostgreSQL; using Core.Entities; using Infrastructure.Data; using Microsoft.EntityFrameworkCore; diff --git a/backend/Infrastructure/obj/Debug/net8.0/Infrastructure.AssemblyInfo.cs b/backend/Infrastructure/obj/Debug/net8.0/Infrastructure.AssemblyInfo.cs index e0f0fd1..d53954b 100644 --- a/backend/Infrastructure/obj/Debug/net8.0/Infrastructure.AssemblyInfo.cs +++ b/backend/Infrastructure/obj/Debug/net8.0/Infrastructure.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("Infrastructure")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [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.AssemblyTitleAttribute("Infrastructure")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/backend/Infrastructure/obj/Debug/net8.0/Infrastructure.AssemblyInfoInputs.cache b/backend/Infrastructure/obj/Debug/net8.0/Infrastructure.AssemblyInfoInputs.cache index ce91f1c..d70394b 100644 --- a/backend/Infrastructure/obj/Debug/net8.0/Infrastructure.AssemblyInfoInputs.cache +++ b/backend/Infrastructure/obj/Debug/net8.0/Infrastructure.AssemblyInfoInputs.cache @@ -1 +1 @@ -90add3a549a5ad86ae4df2628a148c5a9756bdaa56fd8988b963942aa2b42329 +30fec65cc45becf276dcf8ed6696bf02cadfb1a90989db6bf5e21ba21d2c8f27