This commit is contained in:
andrei-mihnea-cerbu
2024-04-08 00:03:24 +03:00
parent 2ccec617a5
commit b48d5ee19e
168 changed files with 2877 additions and 1146 deletions
+51 -88
View File
@@ -1,117 +1,80 @@
using Microsoft.AspNetCore.Mvc;
using Core.Entities;
using Application.Endpoints;
using Application.Endpoints.Doctors.Login;
using Application.Services.Database;
using Application.Endpoints.Doctors.Profile;
using Application.Endpoints.Doctors.Registration;
using Application.Endpoints.Doctors.ResetPassword;
using Application.Endpoints.Doctors.Profile;
using Application.Services.Database;
using Application.Services.HashingAlgorithms;
using Microsoft.AspNetCore.Mvc;
namespace HealthcareManager.API.Controllers;
namespace API.Controllers;
[ApiController]
[Route("api/[controller]")]
public class DoctorsController : ControllerBase
{
private readonly IDoctorRepository _database;
private readonly IHashingAlgorithms _hashingAlgorithms;
public DoctorsController(IDoctorRepository database)
public DoctorsController(IDoctorRepository database, IHashingAlgorithms hashingAlgorithms)
{
_database = database ?? throw new ArgumentNullException(nameof(database));
}
[HttpGet]
public async Task<ActionResult<Doctor>> GetAllDoctors()
{
var handler = new DoctorProfileHandler(_database);
var response = await handler.HandleGetAll();
if (!response.Success)
{
return BadRequest(response);
}
return Ok(response.Data);
}
[HttpGet("{id}")]
public async Task<ActionResult<Doctor>> GetDoctor(Guid id)
{
var handler = new DoctorProfileHandler(_database);
var response = await handler.HandleGet(id);
if (!response.Success)
{
return BadRequest(response);
}
return Ok(response.Data);
}
[HttpPost("login")]
public async Task<ActionResult<Doctor>> Login(DoctorLoginDTO doctor)
{
var handler = new DoctorLoginHandler(_database);
var response = await handler.Handle(doctor).ConfigureAwait(false);
if(!response.Success)
{
return Unauthorized(response);
}
return Ok(response);
_database = database;
_hashingAlgorithms = hashingAlgorithms;
}
[HttpPost("register")]
public async Task<ActionResult<Doctor>> Register(DoctorRegistrationDto doctor)
public async Task<ActionResult<BaseResponse>> Register(DoctorRegistrationDto doctor)
{
var handler = new DoctorRegistrationHandler(_database);
var handler = new DoctorRegistrationHandler(_database, _hashingAlgorithms);
var response = await handler.Handle(doctor).ConfigureAwait(false);
if (!response.Success)
{
return Unauthorized(response);
}
return Ok(response);
return StatusCode(response.StatusCode, response);
}
[HttpPost("resetPassword")]
public async Task<IActionResult> ResetPassword(DoctorLoginDTO resetDoctorDto)
[HttpPost("login")]
public async Task<ActionResult<BaseResponse>> Login(DoctorLoginDto doctor)
{
var handler = new DoctorResetPasswordHandler(_database);
var handler = new DoctorLoginHandler(_database, _hashingAlgorithms);
var response = await handler.Handle(doctor).ConfigureAwait(false);
return StatusCode(response.StatusCode, response);
}
[HttpPost("reset_password")]
public async Task<ActionResult<BaseResponse>> ResetPassword(DoctorResetPasswordDto resetDoctorDto)
{
var handler = new DoctorResetPasswordHandler(_database, _hashingAlgorithms);
var response = await handler.Handle(resetDoctorDto).ConfigureAwait(false);
if (response.Success)
{
return Ok(response);
}
return BadRequest(response);
return StatusCode(response.StatusCode, response);
}
[HttpPut("{id}/profile")]
public async Task<IActionResult> UpdateDoctorProfile(Guid id, [FromBody]DoctorProfileDTO doctorDto)
[HttpGet]
public async Task<ActionResult<BaseResponse>> GetAllDoctors()
{
var handler = new DoctorProfileHandler(_database);
var response = await handler.HandleUpdate(id, doctorDto).ConfigureAwait(false);
if (response.Success)
{
return Ok(response);
}
return BadRequest(response);
var handler = new DoctorProfileHandler(_database, _hashingAlgorithms);
var response = await handler.HandleGetAll();
return StatusCode(response.StatusCode, response);
}
[HttpDelete("{id}/profile")]
public async Task<IActionResult> DeleteDoctorProfile(Guid id)
[HttpGet("{id}")]
public async Task<ActionResult<BaseResponse>> GetDoctor(Guid id)
{
var handler = new DoctorProfileHandler(_database);
var handler = new DoctorProfileHandler(_database, _hashingAlgorithms);
var response = await handler.HandleGet(id);
return StatusCode(response.StatusCode, response);
}
[HttpPut]
public async Task<ActionResult<BaseResponse>> UpdateDoctorProfile(DoctorProfileUpdateDto doctorUpdateDto)
{
var handler = new DoctorProfileHandler(_database, _hashingAlgorithms);
var response = await handler.HandleUpdate(doctorUpdateDto).ConfigureAwait(false);
return StatusCode(response.StatusCode, response);
}
[HttpDelete("{id}")]
public async Task<ActionResult<BaseResponse>> DeleteDoctorProfile(Guid id)
{
var handler = new DoctorProfileHandler(_database, _hashingAlgorithms);
var response = await handler.HandleDelete(id).ConfigureAwait(false);
if (response.Success)
{
return NoContent();
}
return BadRequest(response);
return StatusCode(response.StatusCode, response);
}
}
}