Manage Appointments DONE!

This commit is contained in:
andrei-mihnea-cerbu
2024-04-08 21:29:18 +03:00
parent 8663a186a0
commit 13bfa2bdd9
91 changed files with 762 additions and 52 deletions
@@ -0,0 +1,59 @@
using Application.Endpoints.Appointments;
using Application.Services.Database.MongoDB;
using Core.Entities;
namespace Infrastructure.Services.MongoDB;
public class AppointmentsMongoDbService : MongoDbService, IAppointmentsMongoDbService
{
public AppointmentsMongoDbService(string connectionString, string databaseName, string collectionName)
: base(connectionString, databaseName, collectionName)
{
}
public async Task<bool> 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<Appointment>(criteria);
foreach (var app in appointments)
{
if (app.AppointmentsList.Any(a => a.Date == appointment.Date))
{
return false;
}
}
return true;
}
public async Task<bool> 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<Appointment>(criteria);
foreach (var app in appointments)
{
if (app.AppointmentsList.Any(a => a.Date == appointment.Date))
{
return true;
}
}
return false;
}
}
@@ -70,5 +70,12 @@ namespace Infrastructure.Services.MongoDB
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);
}
}
}