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

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