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

61 lines
2.5 KiB
C#

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