80 lines
3.2 KiB
C#
80 lines
3.2 KiB
C#
using Application.Endpoints;
|
|
using Application.Endpoints.Patients.Login;
|
|
using Application.Endpoints.Patients.Profile;
|
|
using Application.Endpoints.Patients.Registration;
|
|
using Application.Endpoints.Patients.ResetPassword;
|
|
using Application.Services.Database;
|
|
using Application.Services.HashingAlgorithms;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace API.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class PatientsController : ControllerBase
|
|
{
|
|
private readonly IHashingAlgorithms _hashingAlgorithms;
|
|
private readonly IPatientRepository _patientRepository;
|
|
|
|
public PatientsController(IPatientRepository patientRepository, IHashingAlgorithms hashingAlgorithms)
|
|
{
|
|
_patientRepository = patientRepository;
|
|
_hashingAlgorithms = hashingAlgorithms;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<ActionResult<BaseResponse>> GetAllPatients()
|
|
{
|
|
var handler = new PatientProfileHandler(_patientRepository, _hashingAlgorithms);
|
|
var response = await handler.HandleGetAll();
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
public async Task<ActionResult<BaseResponse>> GetPatient(Guid id)
|
|
{
|
|
var handler = new PatientProfileHandler(_patientRepository, _hashingAlgorithms);
|
|
var response = await handler.HandleGet(id);
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[HttpPost("login")]
|
|
public async Task<ActionResult<BaseResponse>> Login(PatientLoginDto patientLoginDto)
|
|
{
|
|
var handler = new PatientLoginHandler(_patientRepository);
|
|
var response = await handler.Handle(patientLoginDto).ConfigureAwait(false);
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[HttpPost("register")]
|
|
public async Task<ActionResult<BaseResponse>> Register(PatientRegistrationDto patientRegistrationDto)
|
|
{
|
|
var handler = new PatientRegistrationHandler(_patientRepository, _hashingAlgorithms);
|
|
var response = await handler.Handle(patientRegistrationDto).ConfigureAwait(false);
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[HttpPost("reset_password")]
|
|
public async Task<ActionResult<BaseResponse>> ResetPassword(PatientResetPasswordDto patientResetPasswordDto)
|
|
{
|
|
var handler = new PatientResetPasswordHandler(_patientRepository, _hashingAlgorithms);
|
|
var response = await handler.Handle(patientResetPasswordDto).ConfigureAwait(false);
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[HttpPut]
|
|
public async Task<ActionResult<BaseResponse>> UpdatePatientProfile(PatientProfileDto patientDto)
|
|
{
|
|
var handler = new PatientProfileHandler(_patientRepository, _hashingAlgorithms);
|
|
var response = await handler.HandleUpdate(patientDto).ConfigureAwait(false);
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[HttpDelete("{id}")]
|
|
public async Task<ActionResult<BaseResponse>> DeletePatientProfile(Guid id)
|
|
{
|
|
var handler = new PatientProfileHandler(_patientRepository, _hashingAlgorithms);
|
|
var response = await handler.HandleDelete(id).ConfigureAwait(false);
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
} |