24 lines
716 B
C#
24 lines
716 B
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using QuestionsApi.Services;
|
|
using System.Security.Claims;
|
|
|
|
namespace QuestionsApi.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/dashboard")]
|
|
[Authorize(Roles = "USER,SUPER")]
|
|
public sealed class DashboardController(DashboardStore dashboard) : ControllerBase
|
|
{
|
|
[HttpGet]
|
|
public async Task<IActionResult> Get()
|
|
{
|
|
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier)
|
|
?? User.FindFirstValue(ClaimTypes.Name)
|
|
?? User.Identity?.Name
|
|
?? "";
|
|
if (string.IsNullOrWhiteSpace(userId)) return Unauthorized();
|
|
return Ok(await dashboard.GetAsync(userId, DateTime.UtcNow));
|
|
}
|
|
}
|