using Application.Endpoints; using Application.Endpoints.Patients.DeletePatient; using Application.Endpoints.Patients.ModifyPatient; using Application.Endpoints.Patients.QuerriesPatients; 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 PatientsController( IPatientRepository patientRepository, IDoctorRepository doctorRepository, IAdminRepository adminRepository, IEncryptionService encryptionService, IMedicalHistoryRepository medicalHistory, IMedicalHistoryMongoDbService medicalHistoryMongoDbService) : ControllerBase { [Authorize(Policy = Policies.AuthenticatedPolicy)] [HttpGet] public async Task> GetAllPatients(CancellationToken token) { var handler = new QuerriesPatientsHandle(patientRepository); var response = await handler.HandleGetAll(token); return StatusCode(response.StatusCode, response); } [Authorize(Policy = Policies.AuthenticatedPolicy)] [HttpGet("{id}")] public async Task> GetPatient(Guid id, CancellationToken token) { var handler = new QuerriesPatientsHandle(patientRepository); var response = await handler.HandleGet(id, token); if (response.StatusCode == HttpStatusCodes.NotFound) return NotFound(); return StatusCode(response.StatusCode, response); } [Authorize(Policy = Policies.PatientPolicy)] [HttpPut] public async Task> ModifyPatient( ModifyPatientCommand request, CancellationToken token) { var handler = new ModifyPatientHandler(encryptionService, patientRepository, doctorRepository, adminRepository); var response = await handler.Handle(request, token); if (response.StatusCode == HttpStatusCodes.NoContent) return NoContent(); return StatusCode(response.StatusCode, response); } [Authorize(Policy = Policies.PatientPolicy)] [HttpDelete("{id}")] public async Task> DeletePatientProfile(Guid id, CancellationToken token) { var handler = new DeletePatientHandler(patientRepository, medicalHistory, medicalHistoryMongoDbService); var response = await handler.Handle(id, token); if (response.StatusCode == HttpStatusCodes.NoContent) return NoContent(); return StatusCode(response.StatusCode, response); } }