using Microsoft.AspNetCore.Mvc; 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; [ApiController] [Route("api/[controller]")] public class DoctorsController : ControllerBase { private readonly IDoctorRepository _database; public DoctorsController(IDoctorRepository database) { _database = database ?? throw new ArgumentNullException(nameof(database)); } [HttpGet] public async Task> 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> 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> 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); } [HttpPost("register")] public async Task> 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 ResetPassword(DoctorLoginDTO resetDoctorDto) { var handler = new DoctorResetPasswordHandler(_database); var response = await handler.Handle(resetDoctorDto).ConfigureAwait(false); if (response.Success) { return Ok(response); } return BadRequest(response); } [HttpPut("{id}/profile")] public async Task UpdateDoctorProfile(Guid id, [FromBody]DoctorProfileDTO doctorDto) { var handler = new DoctorProfileHandler(_database); var response = await handler.HandleUpdate(id, doctorDto).ConfigureAwait(false); if (response.Success) { return Ok(response); } return BadRequest(response); } [HttpDelete("{id}/profile")] public async Task DeleteDoctorProfile(Guid id) { var handler = new DoctorProfileHandler(_database); var response = await handler.HandleDelete(id).ConfigureAwait(false); if (response.Success) { return NoContent(); } return BadRequest(response); } }