finalizare 1.0
This commit is contained in:
@@ -1,46 +1,36 @@
|
||||
using Application.Endpoints.Appointments;
|
||||
using Application.Services.Database.MongoDB;
|
||||
using Core.Entities;
|
||||
using Application.Services.Database.MongoDB;
|
||||
using Domain.Entities;
|
||||
using MongoDB.Driver;
|
||||
using Application.Endpoints.Appointments;
|
||||
|
||||
namespace Infrastructure.Services.MongoDB;
|
||||
|
||||
public class AppointmentsMongoDbService : MongoDbService, IAppointmentsMongoDbService
|
||||
public class AppointmentsMongoDbService(string connectionString, string databaseName, string collectionName)
|
||||
: MongoDbService(connectionString, databaseName, collectionName), IAppointmentsMongoDbService
|
||||
{
|
||||
public AppointmentsMongoDbService(string connectionString, string databaseName, string collectionName)
|
||||
: base(connectionString, databaseName, collectionName)
|
||||
public async Task<bool> IsAppointmentUnique(AppointmentInformation request, CancellationToken token)
|
||||
{
|
||||
}
|
||||
var criteria = new List<(string FieldName, string Value)>
|
||||
{
|
||||
("DoctorId", request.DoctorId.ToString()),
|
||||
("PatientId", request.PatientId.ToString())
|
||||
};
|
||||
|
||||
public async Task<bool> IsAppointmentUnique(AppointmentManagementDto dto)
|
||||
var appointments = await FindAsync<Appointment>(criteria, token);
|
||||
return appointments.All(a => !a.AppointmentsList.Any(dt => dt == request.Appointment));
|
||||
}
|
||||
|
||||
public async Task<bool> DoesAppointmentExists(AppointmentInformation request, CancellationToken token)
|
||||
{
|
||||
var appointment = dto.Appointment.ToUniversalTime();
|
||||
var appointment = request.Appointment.ToUniversalTime();
|
||||
|
||||
var criteria = new List<(string FieldName, string Value)>
|
||||
{
|
||||
("DoctorId", dto.DoctorId.ToString()),
|
||||
("PatientId", dto.PatientId.ToString())
|
||||
("DoctorId", request.DoctorId.ToString()),
|
||||
("PatientId", request.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);
|
||||
var appointments = await FindAsync<Appointment>(criteria, token);
|
||||
|
||||
foreach (var app in appointments)
|
||||
if (app.AppointmentsList.Any(a => a.Date == appointment.Date))
|
||||
@@ -48,4 +38,27 @@ public class AppointmentsMongoDbService : MongoDbService, IAppointmentsMongoDbSe
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<List<Appointment>> FindPastAppointments(DateTime currentDate, CancellationToken token)
|
||||
{
|
||||
var filterBuilder = Builders<Appointment>.Filter;
|
||||
var filter = filterBuilder.Lt("AppointmentsList", currentDate);
|
||||
|
||||
return await GetCollection<Appointment>().Find(filter).ToListAsync(token);
|
||||
}
|
||||
|
||||
public async Task UpdateAppointment(Appointment appointment, CancellationToken token)
|
||||
{
|
||||
await ModifyAsync("_id", appointment.Id, appointment, token);
|
||||
}
|
||||
|
||||
public async Task DeleteAppointment(string appointmentId, CancellationToken token)
|
||||
{
|
||||
await DeleteByIdAsync<Appointment>(appointmentId, token);
|
||||
}
|
||||
|
||||
public async Task<List<Appointment>> GetAllAppointments(CancellationToken token)
|
||||
{
|
||||
return await GetCollection<Appointment>().Find(Builders<Appointment>.Filter.Empty).ToListAsync(token);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user