Manage Appointments DONE!
This commit is contained in:
@@ -4,6 +4,7 @@ using Application.Endpoints.Doctors.Profile;
|
||||
using Application.Endpoints.Doctors.Registration;
|
||||
using Application.Endpoints.Doctors.ResetPassword;
|
||||
using Application.Services.Database;
|
||||
using Application.Services.Database.MongoDB;
|
||||
using Application.Services.HashingAlgorithms;
|
||||
using Application.Services.Jwt;
|
||||
using Core.Entities;
|
||||
@@ -18,13 +19,15 @@ public class DoctorsController : ControllerBase
|
||||
private readonly IDoctorRepository _database;
|
||||
private readonly IHashingAlgorithms _hashingAlgorithms;
|
||||
private readonly IJwtService _jwtService;
|
||||
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
|
||||
|
||||
public DoctorsController(IDoctorRepository database, IHashingAlgorithms hashingAlgorithms,
|
||||
IJwtService jwtService)
|
||||
IJwtService jwtService, IAppointmentsMongoDbService appointmentsMongoDbService)
|
||||
{
|
||||
_database = database;
|
||||
_hashingAlgorithms = hashingAlgorithms;
|
||||
_jwtService = jwtService;
|
||||
_appointmentsMongoDbService = appointmentsMongoDbService;
|
||||
}
|
||||
|
||||
[HttpPost("register")]
|
||||
@@ -40,6 +43,7 @@ public class DoctorsController : ControllerBase
|
||||
{
|
||||
var handler = new DoctorLoginHandler(_database, _hashingAlgorithms);
|
||||
var response = await handler.Handle(doctorLoginDto).ConfigureAwait(false);
|
||||
/*
|
||||
if (response.Data != null)
|
||||
{
|
||||
Doctor doctor = (Doctor)response.Data;
|
||||
@@ -47,6 +51,7 @@ public class DoctorsController : ControllerBase
|
||||
|
||||
HttpContext.Response.Headers.Add("Authorization", $"Bearer {authToken}");
|
||||
}
|
||||
*/
|
||||
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
@@ -125,6 +130,26 @@ public class DoctorsController : ControllerBase
|
||||
{
|
||||
var handler = new DoctorProfileHandler(_database, _hashingAlgorithms);
|
||||
var response = await handler.HandleDelete(id).ConfigureAwait(false);
|
||||
|
||||
if (response.StatusCode < HttpStatusCodes.BadRequest)
|
||||
{
|
||||
DeleteDoctorAppointments(id);
|
||||
}
|
||||
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
|
||||
private async void DeleteDoctorAppointments(Guid doctorId)
|
||||
{
|
||||
var criteria = new List<(string FieldName, string Value)>
|
||||
{
|
||||
("DoctorId", doctorId.ToString())
|
||||
};
|
||||
var appointments = await _appointmentsMongoDbService.FindAsync<Appointment>(criteria);
|
||||
if (!appointments.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
await _appointmentsMongoDbService.DeleteByIdAsync<Appointment>(appointments[0].Id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user