api v2.0
This commit is contained in:
@@ -10,5 +10,4 @@ public class ChatController : BaseApiController
|
||||
{
|
||||
_mongoDbService = mongoDbService;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,67 +1,71 @@
|
||||
using Application.Endpoints.MedicalHistories;
|
||||
using Application.Endpoints;
|
||||
using Application.Endpoints.MedicalHistories;
|
||||
using Application.Services.Database;
|
||||
using Core.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace HealthcareManager.API.Controllers;
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class MedicalHistoryController : ControllerBase
|
||||
{
|
||||
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
|
||||
private readonly IPacientRepository _pacientRepository;
|
||||
private readonly IMongoDbService _mongoDbService;
|
||||
private readonly IPatientRepository _patientRepository;
|
||||
|
||||
public MedicalHistoryController(IMedicalHistoryRepository medicalHistoryRepository, IPacientRepository pacientRepository)
|
||||
public MedicalHistoryController(IMedicalHistoryRepository medicalHistoryRepository,
|
||||
IPatientRepository patientRepository, IMongoDbService mongoDbService)
|
||||
{
|
||||
_medicalHistoryRepository = medicalHistoryRepository ?? throw new ArgumentNullException(nameof(medicalHistoryRepository));
|
||||
_pacientRepository = pacientRepository ?? throw new ArgumentNullException(nameof(pacientRepository));
|
||||
_medicalHistoryRepository = medicalHistoryRepository;
|
||||
_patientRepository = patientRepository;
|
||||
_mongoDbService = mongoDbService;
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<MedicalHistory>> GetAsync(Guid id)
|
||||
public async Task<ActionResult<BaseResponse>> GetAsync(Guid id)
|
||||
{
|
||||
var handler = new MedicalHistoryHandler(_medicalHistoryRepository, _pacientRepository);
|
||||
var handler = new MedicalHistoryHandler(_medicalHistoryRepository, _patientRepository, _mongoDbService);
|
||||
var response = await handler.HandleGet(id);
|
||||
if (!response.Success)
|
||||
{
|
||||
return BadRequest(response);
|
||||
}
|
||||
|
||||
return Ok(response.Data);
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
|
||||
[HttpPost("{id}")]
|
||||
public async Task<ActionResult<MedicalHistory>> PostAsync(Guid id, [FromBody] byte[] description)
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<BaseResponse>> GetAllDoctors()
|
||||
{
|
||||
var handler = new MedicalHistoryHandler(_medicalHistoryRepository, _pacientRepository);
|
||||
var response = await handler.HandleCreate(id, description).ConfigureAwait(false);
|
||||
|
||||
if (!response.Success)
|
||||
{
|
||||
return Unauthorized(response);
|
||||
}
|
||||
|
||||
return Ok(response);
|
||||
var handler = new MedicalHistoryHandler(_medicalHistoryRepository, _patientRepository, _mongoDbService);
|
||||
var response = await handler.HandleGetAll();
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> UpdateAsync(Guid id, [FromBody] MedicalHistoryDTO medicalHistoryDTO)
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<BaseResponse>> PostAsync(MedicalHistoryCreateDto medicalHistoryCreateDto)
|
||||
{
|
||||
var handler = new MedicalHistoryHandler(_medicalHistoryRepository, _pacientRepository);
|
||||
var response = await handler.HandleUpdate(id, medicalHistoryDTO).ConfigureAwait(false);
|
||||
|
||||
if (response.Success)
|
||||
{
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
return BadRequest(response);
|
||||
var handler = new MedicalHistoryHandler(_medicalHistoryRepository, _patientRepository, _mongoDbService);
|
||||
var response = await handler.HandleCreate(medicalHistoryCreateDto);
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public async Task<ActionResult<BaseResponse>> UpdateAsync(MedicalHistoryUpdateDto medicalHistoryUpdateDto)
|
||||
{
|
||||
var handler = new MedicalHistoryHandler(_medicalHistoryRepository, _patientRepository, _mongoDbService);
|
||||
var response = await handler.HandleUpdate(medicalHistoryUpdateDto).ConfigureAwait(false);
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<ActionResult<BaseResponse>> DeleteAsync(Guid id)
|
||||
{
|
||||
var handler = new MedicalHistoryHandler(_medicalHistoryRepository, _patientRepository, _mongoDbService);
|
||||
var response = await handler.HandleDelete(id);
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
|
||||
/*
|
||||
[HttpPut("grant_access")]
|
||||
public async Task<IActionResult> GrantAccessToMedicalHistory(Guid id)
|
||||
public async Task<ActionResult<BaseResponse>> GrantAccessToMedicalHistory(GrantAccessMedicalHistoryDto)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
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;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class PacientsController : ControllerBase
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user