-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathAppointmentController.cs
71 lines (62 loc) · 2.91 KB
/
AppointmentController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
namespace DentallApp.Features.Appointments;
[Route("appointment")]
[ApiController]
public class AppointmentController : ControllerBase
{
private readonly IAppointmentService _appointmentService;
private readonly IAppointmentRepository _appointmentRepository;
public AppointmentController(IAppointmentService appointmentService, IAppointmentRepository appointmentRepository)
{
_appointmentService = appointmentService;
_appointmentRepository = appointmentRepository;
}
/// <summary>
/// Obtiene el historial de citas del usuario básico.
/// </summary>
[AuthorizeByRole(RolesName.BasicUser)]
[HttpGet("basic-user")]
public async Task<IEnumerable<AppointmentGetByBasicUserDto>> GetAppointmentsByUserId()
=> await _appointmentRepository.GetAppointmentsByUserIdAsync(User.GetUserId());
/// <summary>
/// Crea una cita médica para cualquier persona.
/// </summary>
[AuthorizeByRole(RolesName.Secretary)]
[HttpPost]
public async Task<ActionResult<Response<DtoBase>>> Post([FromBody]AppointmentInsertDto appointmentInsertDto)
{
var response = await _appointmentService.CreateAppointmentAsync(appointmentInsertDto);
if (response.Success)
return CreatedAtAction(nameof(Post), response);
return BadRequest(response);
}
/// <summary>
/// Actualiza el estado de una cita por su ID.
/// </summary>
[AuthorizeByRole(RolesName.Secretary, RolesName.Dentist, RolesName.Admin, RolesName.Superadmin)]
[HttpPut("{id}")]
public async Task<ActionResult<Response>> Put(int id, [FromBody]AppointmentUpdateDto appointmentUpdateDto)
{
var response = await _appointmentService.UpdateAppointmentAsync(id, User, appointmentUpdateDto);
if (response.Success)
return Ok(response);
return BadRequest(response);
}
/// <summary>
/// Obtiene las citas de los odontólogos para un empleado.
/// </summary>
/// <remarks>
/// Detalles a tomar en cuenta:
/// <para>- Sí <see cref="AppointmentPostDateDto.OfficeId"/> es <c>0</c>, traerá las citas de TODOS los consultorios.</para>
/// <para>- Sí <see cref="AppointmentPostDateDto.DentistId"/> es <c>0</c>, traerá las citas de TODOS los odontólogos.</para>
/// <para>- Sí <see cref="AppointmentPostDateDto.StatusId"/> es <c>0</c>, traerá las citas de TODOS los estados.</para>
/// </remarks>
[AuthorizeByRole(RolesName.Secretary, RolesName.Dentist, RolesName.Admin, RolesName.Superadmin)]
[HttpPost("dentist")]
public async Task<ActionResult<Response<IEnumerable<AppointmentGetByEmployeeDto>>>> GetAppointmentsForEmployee([FromBody]AppointmentPostDateDto appointmentPostDto)
{
var response = await _appointmentService.GetAppointmentsForEmployeeAsync(User, appointmentPostDto);
if (response.Success)
return Ok(response);
return BadRequest(response);
}
}