Files
FACULTATE-HEALTHCARE_MANAGER/backend/API/Controllers/PatientsController.cs
T
2024-05-30 15:40:13 +03:00

64 lines
2.6 KiB
C#

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<ActionResult<BaseResponse>> 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<ActionResult<BaseResponse>> 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<ActionResult<BaseResponse>> 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<ActionResult<BaseResponse>> 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);
}
}