using System.ComponentModel.DataAnnotations; using Asp.Versioning; using Baya.Application.Features.Identity.Commands.ArchivePatient; using Baya.Application.Features.Identity.Commands.CreatePatient; using Baya.Application.Features.Identity.Commands.UpdatePatient; using Baya.Application.Features.Identity.Queries.GetPatient; using Baya.Application.Features.Identity.Queries.ListPatients; using Baya.Application.Models.Common; using Baya.Application.Models.Identity; using Baya.WebFramework.Attributes; using Baya.WebFramework.BaseController; using Mediator; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace Baya.Web.Api.Controllers.V1; [ApiVersion("1")] [ApiController] [Route("api/v{version:apiVersion}/[controller]")] [Authorize] [Display(Description = "The signed-in customer's patients (care recipients)")] public sealed class PatientsController(ISender sender) : BaseController { [HttpPost("[action]")] [ProducesOkApiResponseType] public async Task Create(CreatePatientCommand command, CancellationToken cancellationToken) => OperationResult(await sender.Send(command, cancellationToken)); [HttpGet("[action]")] [ProducesOkApiResponseType>] public async Task List([FromQuery] ListPatientsQuery query, CancellationToken cancellationToken) => OperationResult(await sender.Send(query, cancellationToken)); [HttpGet("[action]/{id}")] [ProducesOkApiResponseType] public async Task Get(long id, CancellationToken cancellationToken) => OperationResult(await sender.Send(new GetPatientQuery(id), cancellationToken)); [HttpPost("[action]/{id}")] [ProducesOkApiResponseType] public async Task Update(long id, UpdatePatientCommand command, CancellationToken cancellationToken) => OperationResult(await sender.Send(command with { Id = id }, cancellationToken)); [HttpPost("[action]/{id}")] [ProducesOkApiResponseType] public async Task Archive(long id, CancellationToken cancellationToken) => OperationResult(await sender.Send(new ArchivePatientCommand(id), cancellationToken)); }