finalizare 1.0
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using Application.Services.Database.MongoDB;
|
||||
using Application.Services.Database.PostgreSQL;
|
||||
using Domain.Entities;
|
||||
|
||||
namespace Application.Endpoints.Doctors.DeleteDoctor;
|
||||
|
||||
public class DeleteDoctorHandler(
|
||||
IDoctorRepository doctorRepository,
|
||||
IAppointmentsMongoDbService appointmentsMongoDbService)
|
||||
{
|
||||
public async Task<BaseResponse> Handle(Guid id, CancellationToken token)
|
||||
{
|
||||
var doctor = await doctorRepository.GetByIdAsync(id, token);
|
||||
if (doctor == null)
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.NotFound,
|
||||
Message = "Doctor was not found.",
|
||||
Data = null
|
||||
};
|
||||
|
||||
await doctorRepository.DeleteAsync(doctor, token);
|
||||
var criteria = new List<(string FieldName, string Value)>
|
||||
{
|
||||
("DoctorId", id.ToString())
|
||||
};
|
||||
var appointments = await appointmentsMongoDbService.FindAsync<Appointment>(criteria, token);
|
||||
if (appointments.Count != 0)
|
||||
await appointmentsMongoDbService.DeleteByIdAsync<Appointment>(appointments[0].Id, token);
|
||||
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.NoContent,
|
||||
Message = null,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user