26 lines
857 B
C#
26 lines
857 B
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using QuestionsApi.Services;
|
|
using System.Security.Claims;
|
|
|
|
namespace QuestionsApi.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/weekly-goals")]
|
|
[Authorize(Roles = "USER,SUPER")]
|
|
public sealed class WeeklyGoalsController(
|
|
WeeklyGoalStore goals, DashboardStore dashboard, QuestionStore questions) : ControllerBase
|
|
{
|
|
[HttpGet]
|
|
public async Task<IActionResult> Get()
|
|
{
|
|
var userId = UserId();
|
|
var now = DateTime.UtcNow;
|
|
return Ok(await goals.GetAsync(userId, await dashboard.GetAsync(userId, now),
|
|
await questions.GetPublishedAsync()));
|
|
}
|
|
|
|
private string UserId() => User.FindFirstValue(ClaimTypes.NameIdentifier)
|
|
?? User.FindFirstValue(ClaimTypes.Name) ?? User.Identity?.Name ?? throw new UnauthorizedAccessException();
|
|
}
|