using System.ComponentModel.DataAnnotations; using Asp.Versioning; using Baya.Application.Features.Identity.Commands.SelectRole; using Baya.Application.Features.Identity.Queries.GetMe; 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 user's identity, roles and role selection")] public sealed class MeController(ISender sender) : BaseController { [HttpGet] [ProducesOkApiResponseType] public async Task GetMe(CancellationToken cancellationToken) => OperationResult(await sender.Send(new GetMeQuery(), cancellationToken)); /// Role claims live inside the access token — after selecting a role the client should /// refresh its tokens to pick the new role up. [HttpPost("[action]")] [ProducesOkApiResponseType] public async Task SelectRole(SelectRoleCommand command, CancellationToken cancellationToken) => OperationResult(await sender.Send(command, cancellationToken)); }