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,38 @@
using Application.Endpoints;
using Application.Endpoints.Appointments;
using Application.Services.Database;
using Application.Services.Database.MongoDB;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers;
public class AppointmentsController : BaseApiController
{
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
private readonly IPatientRepository _patientRepository;
private readonly IDoctorRepository _doctorRepository;
public AppointmentsController(IAppointmentsMongoDbService appointmentsMongoDbService,
IPatientRepository patientRepository, IDoctorRepository doctorRepository)
{
_appointmentsMongoDbService = appointmentsMongoDbService;
_patientRepository = patientRepository;
_doctorRepository = doctorRepository;
}
[HttpPost]
public async Task<ActionResult<BaseResponse>> CreateAppointment(AppointmentManagementDto dto)
{
var handler = new AppointmentManagementHandler(_appointmentsMongoDbService, _patientRepository, _doctorRepository);
var response = await handler.HandleCreateAppointment(dto).ConfigureAwait(false);
return StatusCode(response.StatusCode, response);
}
[HttpDelete]
public async Task<ActionResult<BaseResponse>> DeleteAppointment(AppointmentManagementDto dto)
{
var handler = new AppointmentManagementHandler(_appointmentsMongoDbService, _patientRepository, _doctorRepository);
var response = await handler.HandleDeleteAppointment(dto).ConfigureAwait(false);
return StatusCode(response.StatusCode, response);
}
}
+26 -1
View File
@@ -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);
}
}
@@ -48,6 +48,7 @@ public class PatientsController : ControllerBase
{
var handler = new PatientLoginHandler(_patientRepository);
var response = await handler.Handle(patientLoginDto).ConfigureAwait(false);
/*
if (response.Data != null)
{
Patient patient = (Patient)response.Data;
@@ -55,6 +56,7 @@ public class PatientsController : ControllerBase
HttpContext.Response.Headers.Add("Authorization", $"Bearer {authToken}");
}
*/
return StatusCode(response.StatusCode, response);
}