using Application.Endpoints; using Application.Endpoints.Appointments; using Application.Endpoints.Appointments.CreateAppointment; using Application.Endpoints.Appointments.DeleteAppointment; using Application.Endpoints.Appointments.QuerriesAppointments; using Application.Services.Database.MongoDB; using Application.Services.Database.PostgreSQL; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace API.Controllers; [Route("api/[controller]")] public class AppointmentsController( IAppointmentsMongoDbService appointmentsMongoDbService, IPatientRepository patientRepository, IDoctorRepository doctorRepository) : BaseApiController { [Authorize(Policy = Policies.ClientsOnlyPolicy)] [HttpPost] public async Task> CreateAppointment(AppointmentInformation request, CancellationToken token) { var handler = new CreateAppointmentHandler(appointmentsMongoDbService, patientRepository, doctorRepository); var response = await handler.Handle(request, token); return StatusCode(response.StatusCode, response); } [Authorize(Policy = Policies.ClientsOnlyPolicy)] [HttpPut] public async Task> DeleteAppointment(AppointmentInformation request, CancellationToken token) { var handler = new DeleteAppointmentHandler(appointmentsMongoDbService, patientRepository, doctorRepository); var response = await handler.Handle(request, token); return StatusCode(response.StatusCode, response); } [Authorize(Policy = Policies.ClientsOnlyPolicy)] [HttpGet("patient/{id:guid}")] public async Task> GetAppointmentsByPatient(Guid id, CancellationToken token) { var handler = new QuerriesAppointmentHandler(appointmentsMongoDbService); var response = await handler.GetByPatientId(id, token); return StatusCode(response.StatusCode, response); } [Authorize(Policy = Policies.ClientsOnlyPolicy)] [HttpGet("doctor/{id:guid}")] public async Task> GetAppointmentsByDoctor(Guid id, CancellationToken token) { var handler = new QuerriesAppointmentHandler(appointmentsMongoDbService); var response = await handler.GetsByDoctorId(id, token); return StatusCode(response.StatusCode, response); } }