Files
FACULTATE-HEALTHCARE_MANAGER/backend/API/Controllers/PatientsController.cs
T
2024-05-21 12:10:53 +03:00

74 lines
2.7 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.Email;
using Application.Services.HashingAlgorithms;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers;
[ApiController]
[Route("api/[controller]")]
public class PatientsController(
IPatientRepository patientRepository,
IDoctorRepository doctorRepository,
IAdminRepository adminRepository,
IHashingAlgorithms hashingAlgorithms,
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(hashingAlgorithms,
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);
}
}