This commit is contained in:
andrei-mihnea-cerbu
2024-04-08 02:31:05 +03:00
parent 61a55fa735
commit b4eca98e0a
57 changed files with 185 additions and 105 deletions
@@ -1,4 +1,5 @@
using Application.Services.Database;
using Application.Services.Database.MongoDB;
using Core.Entities;
namespace Application.Endpoints.MedicalHistories;
@@ -6,15 +7,15 @@ namespace Application.Endpoints.MedicalHistories;
public class MedicalHistoryHandler
{
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
private readonly IMongoDbService _mongoDbService;
private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService;
private readonly IPatientRepository _patientRepository;
public MedicalHistoryHandler(IMedicalHistoryRepository medicalHistoryRepository,
IPatientRepository patientRepository, IMongoDbService mongoDbService)
IPatientRepository patientRepository, IMedicalHistoryMongoDbService medicalHistoryMongoDbService)
{
_medicalHistoryRepository = medicalHistoryRepository;
_patientRepository = patientRepository;
_mongoDbService = mongoDbService;
_medicalHistoryMongoDbService = medicalHistoryMongoDbService;
}
public async Task<BaseResponse> HandleGetAll()
@@ -30,7 +31,7 @@ public class MedicalHistoryHandler
return new BaseResponse
{
StatusCode = HttpStatusCodes.NotFound,
StatusCode = HttpStatusCodes.NoContent,
Message = "Medical histories not found",
Data = null
};
@@ -79,19 +80,16 @@ public class MedicalHistoryHandler
UserId = medicalHistoryCreateDto.UserId,
Content = medicalHistoryCreateDto.Content
};
await _medicalHistoryRepository.AddAsync(medicalHistory);
//TODO add to MongoDB
var medicalHistoryId = medicalHistory.Id;
var newMedicalHistory = new MedicalHistoryAuthorisationModel
{
Id = medicalHistoryId,
Authorisation = new List<Guid>()
Id = medicalHistoryId.ToString(),
Authorisation = new List<string>()
};
await _mongoDbService.AddAsync("MedicalHistory", newMedicalHistory);
await _medicalHistoryMongoDbService.AddAsync(newMedicalHistory);
await _medicalHistoryRepository.AddAsync(medicalHistory);
return new BaseResponse
{
@@ -143,6 +141,8 @@ public class MedicalHistoryHandler
Data = null
};
await _medicalHistoryMongoDbService.DeleteAsync<MedicalHistoryAuthorisationModel>("_id", id.ToString());
await _medicalHistoryRepository.DeleteAsync(medicalRecord);
//TODO delete from MongoDB