medicalHistory: deletion when patient is deleted
This commit is contained in:
@@ -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.Chats;
|
||||
@@ -7,8 +7,8 @@ namespace Application.Endpoints.Chats;
|
||||
public class ChatHandler
|
||||
{
|
||||
private readonly IChatMongoDbService _chatMongoDbService;
|
||||
private readonly IPatientRepository _patientRepository;
|
||||
private readonly IDoctorRepository _doctorRepository;
|
||||
private readonly IPatientRepository _patientRepository;
|
||||
|
||||
public ChatHandler(IChatMongoDbService chatMongoDbService, IPatientRepository patientRepository,
|
||||
IDoctorRepository doctorRepository)
|
||||
@@ -38,30 +38,26 @@ public class ChatHandler
|
||||
}
|
||||
|
||||
if (!await CheckForUsersExistence(sendMessageDto.Sender, sendMessageDto.Receiver))
|
||||
{
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.BadRequest,
|
||||
Message = "Users can't be found in the system.",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
|
||||
var chatId = IdentifierGenerator.GenerateId(sendMessageDto.Sender, sendMessageDto.Receiver);
|
||||
|
||||
|
||||
var criteria = new List<(string, string)>();
|
||||
criteria.Add(("_id", chatId));
|
||||
|
||||
var documents = await _chatMongoDbService.FindAsync<Chat>(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<Chat>(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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user