pushed api files

pushed middlewares
This commit is contained in:
ElenitaMLG
2024-04-07 02:49:34 +03:00
parent 55eaa0d53a
commit 2ccec617a5
11 changed files with 390 additions and 54 deletions
+90 -24
View File
@@ -2,50 +2,116 @@
using Core.Entities;
using Application.Endpoints.Doctors.Login;
using Application.Services.Database;
using Application.Endpoints.Doctors.Registration;
using Application.Endpoints.Doctors.ResetPassword;
using Application.Endpoints.Doctors.Profile;
namespace HealthcareManager.API.Controllers
namespace HealthcareManager.API.Controllers;
[ApiController]
[Route("api/[controller]")]
public class DoctorsController : ControllerBase
{
[ApiController]
[Route("api/[controller]")]
public class DoctorsController : ControllerBase
private readonly IDoctorRepository _database;
public DoctorsController(IDoctorRepository database)
{
private readonly IDoctorRepository _database;
_database = database ?? throw new ArgumentNullException(nameof(database));
}
public DoctorsController(IDoctorRepository database)
[HttpGet]
public async Task<ActionResult<Doctor>> GetAllDoctors()
{
var handler = new DoctorProfileHandler(_database);
var response = await handler.HandleGetAll();
if (!response.Success)
{
_database = database ?? throw new ArgumentNullException(nameof(database));
return BadRequest(response);
}
[HttpGet("{id}")]
public async Task<ActionResult<Doctor>> GetDoctor(int id)
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 NotFound();
return BadRequest(response);
}
[HttpPost]
public async Task<ActionResult<Doctor>> Login(DoctorLoginDTO doctor)
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)
{
var handler = new DoctorLoginHandler(_database);
var response = handler.Handle(doctor).Result;
return Unauthorized(response);
}
if(!response.Success)
{
return Unauthorized(response);
}
return Ok(response);
}
[HttpPost("register")]
public async Task<ActionResult<Doctor>> Register(DoctorRegistrationDto doctor)
{
var handler = new DoctorRegistrationHandler(_database);
var response = await handler.Handle(doctor).ConfigureAwait(false);
if (!response.Success)
{
return Unauthorized(response);
}
return Ok(response);
}
[HttpPost("resetPassword")]
public async Task<IActionResult> ResetPassword(DoctorLoginDTO resetDoctorDto)
{
var handler = new DoctorResetPasswordHandler(_database);
var response = await handler.Handle(resetDoctorDto).ConfigureAwait(false);
if (response.Success)
{
return Ok(response);
}
[HttpPut("{id}")]
public async Task<IActionResult> PutDoctor(int id, Doctor doctor)
return BadRequest(response);
}
[HttpPut("{id}/profile")]
public async Task<IActionResult> UpdateDoctorProfile(Guid id, [FromBody]DoctorProfileDTO doctorDto)
{
var handler = new DoctorProfileHandler(_database);
var response = await handler.HandleUpdate(id, doctorDto).ConfigureAwait(false);
if (response.Success)
{
return NotFound();
return Ok(response);
}
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteDoctor(int id)
return BadRequest(response);
}
[HttpDelete("{id}/profile")]
public async Task<IActionResult> DeleteDoctorProfile(Guid id)
{
var handler = new DoctorProfileHandler(_database);
var response = await handler.HandleDelete(id).ConfigureAwait(false);
if (response.Success)
{
return NotFound();
return NoContent();
}
return BadRequest(response);
}
}