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
+111 -3
View File
@@ -1,9 +1,117 @@
using Microsoft.AspNetCore.Mvc;
using Core.Entities;
using Application.Endpoints.Pacients.Login;
using Application.Services.Database;
using Application.Endpoints.Pacients.Registration;
using Application.Endpoints.Pacients.ResetPassword;
using Application.Endpoints.Pacients.Profile;
namespace HealthcareManager.API.Controllers
namespace HealthcareManager.API.Controllers;
[ApiController]
[Route("api/[controller]")]
public class PacientsController : ControllerBase
{
public class PacientsController : BaseApiController
private readonly IPacientRepository _database;
public PacientsController(IPacientRepository database)
{
_database = database ?? throw new ArgumentNullException(nameof(database));
}
[HttpGet]
public async Task<ActionResult<Pacient>> GetAllPacients()
{
var handler = new PacientProfileHandler(_database);
var response = await handler.HandleGetAll();
if (!response.Success)
{
return BadRequest(response);
}
return Ok(response.Data);
}
[HttpGet("{id}")]
public async Task<ActionResult<Pacient>> GetPacient(Guid id)
{
var handler = new PacientProfileHandler(_database);
var response = await handler.HandleGet(id);
if (!response.Success)
{
return BadRequest(response);
}
return Ok(response.Data);
}
[HttpPost("login")]
public async Task<ActionResult<Pacient>> Login(PacientLoginDTO pacient)
{
var handler = new PacientLoginHandler(_database);
var response = await handler.Handle(pacient).ConfigureAwait(false);
if (!response.Success)
{
return Unauthorized(response);
}
return Ok(response);
}
[HttpPost("register")]
public async Task<ActionResult<Pacient>> Register(PacientRegistrationDto pacient)
{
var handler = new PacientRegistrationHandler(_database);
var response = await handler.Handle(pacient).ConfigureAwait(false);
if (!response.Success)
{
return Unauthorized(response);
}
return Ok(response);
}
[HttpPost("resetPassword")]
public async Task<IActionResult> ResetPassword(PacientLoginDTO resetPacientDto)
{
var handler = new PacientResetPasswordHandler(_database);
var response = await handler.Handle(resetPacientDto).ConfigureAwait(false);
if (response.Success)
{
return Ok(response);
}
return BadRequest(response);
}
[HttpPut("{id}/profile")]
public async Task<IActionResult> UpdatePacientProfile(Guid id, [FromBody] PacientProfileDTO pacientDto)
{
var handler = new PacientProfileHandler(_database);
var response = await handler.HandleUpdate(id, pacientDto).ConfigureAwait(false);
if (response.Success)
{
return Ok(response);
}
return BadRequest(response);
}
[HttpDelete("{id}/profile")]
public async Task<IActionResult> DeletePacientProfile(Guid id)
{
var handler = new PacientProfileHandler(_database);
var response = await handler.HandleDelete(id).ConfigureAwait(false);
if (response.Success)
{
return NoContent();
}
return BadRequest(response);
}
}