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

58 lines
2.4 KiB
C#

using Application.Endpoints;
using Application.Endpoints.Appointments;
using Application.Endpoints.Appointments.CreateAppointment;
using Application.Endpoints.Appointments.DeleteAppointment;
using Application.Endpoints.Appointments.QuerriesAppointments;
using Application.Services.Database.MongoDB;
using Application.Services.Database.PostgreSQL;
using Domain;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers;
[Route("api/[controller]")]
public class AppointmentsController(
IAppointmentsMongoDbService appointmentsMongoDbService,
IPatientRepository patientRepository,
IDoctorRepository doctorRepository)
: BaseApiController
{
[Authorize(Policy = Policies.ClientsOnlyPolicy)]
[HttpPost]
public async Task<ActionResult<BaseResponse>> CreateAppointment(AppointmentInformation request,
CancellationToken token)
{
var handler = new CreateAppointmentHandler(appointmentsMongoDbService, patientRepository, doctorRepository);
var response = await handler.Handle(request, token);
return StatusCode(response.StatusCode, response);
}
[Authorize(Policy = Policies.ClientsOnlyPolicy)]
[HttpPut]
public async Task<ActionResult<BaseResponse>> DeleteAppointment(AppointmentInformation request,
CancellationToken token)
{
var handler = new DeleteAppointmentHandler(appointmentsMongoDbService, patientRepository, doctorRepository);
var response = await handler.Handle(request, token);
return StatusCode(response.StatusCode, response);
}
[Authorize(Policy = Policies.ClientsOnlyPolicy)]
[HttpGet("patient/{id:guid}")]
public async Task<ActionResult<BaseResponse>> GetAppointmentsByPatient(Guid id, CancellationToken token)
{
var handler = new QuerriesAppointmentHandler(appointmentsMongoDbService);
var response = await handler.GetByPatientId(id, token);
return StatusCode(response.StatusCode, response);
}
[Authorize(Policy = Policies.ClientsOnlyPolicy)]
[HttpGet("doctor/{id:guid}")]
public async Task<ActionResult<BaseResponse>> GetAppointmentsByDoctor(Guid id, CancellationToken token)
{
var handler = new QuerriesAppointmentHandler(appointmentsMongoDbService);
var response = await handler.GetsByDoctorId(id, token);
return StatusCode(response.StatusCode, response);
}
}