using Application.Endpoints; using Application.Endpoints.Doctors.DeleteDoctor; using Application.Endpoints.Doctors.ModifyDoctor; using Application.Endpoints.Doctors.QuerriesDoctors; using Application.Services.Database.MongoDB; using Application.Services.Database.PostgreSQL; using Application.Services.Encryption; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace API.Controllers; [ApiController] [Route("api/[controller]")] public class DoctorsController( IDoctorRepository doctorRepository, IPatientRepository patientRepository, IAdminRepository adminRepository, IEncryptionService encryptionService, IAppointmentsMongoDbService appointmentsMongoDbService) : ControllerBase { [Authorize(Policy = Policies.AuthenticatedPolicy)] [HttpGet] public async Task> GetAllDoctors(CancellationToken token) { var handler = new QuerriesDoctorsHandler(doctorRepository); var response = await handler.HandleGetAll(token); return StatusCode(response.StatusCode, response); } [Authorize(Policy = Policies.AuthenticatedPolicy)] [HttpGet("{id}")] public async Task> GetDoctor(Guid id, CancellationToken token) { var handler = new QuerriesDoctorsHandler(doctorRepository); var response = await handler.HandleGet(id, token); if (response.StatusCode == HttpStatusCodes.NotFound) return NotFound(); return StatusCode(response.StatusCode, response); } [Authorize(Policy = Policies.DoctorPolicy)] [HttpPut] public async Task> ModifyDoctor(ModifyDoctorCommand request, CancellationToken token) { var handler = new ModifyDoctorHandler(encryptionService, doctorRepository, patientRepository, adminRepository); var response = await handler.Handle(request, token); if (response.StatusCode == HttpStatusCodes.NoContent) return NoContent(); return StatusCode(response.StatusCode, response); } [Authorize(Policy = Policies.DoctorPolicy)] [HttpDelete("{id}")] public async Task> DeleteDoctor(Guid id, CancellationToken token) { var handler = new DeleteDoctorHandler(doctorRepository, appointmentsMongoDbService); var response = await handler.Handle(id, token); if (response.StatusCode == HttpStatusCodes.NoContent) return NoContent(); return StatusCode(response.StatusCode, response); } }