using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using QuestionsApi.Services; using System.Security.Claims; namespace QuestionsApi.Controllers; [ApiController] [Route("api/credits")] [Authorize(Roles = "USER,SUPER")] public sealed class CreditsController(CreditStore credits) : ControllerBase { [HttpGet] public async Task Get() => Ok(await credits.GetStatusAsync(UserId())); private string UserId() => User.FindFirstValue(ClaimTypes.NameIdentifier) ?? User.FindFirstValue(ClaimTypes.Name) ?? User.Identity?.Name ?? throw new UnauthorizedAccessException(); }