using Asp.Versioning; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using TarninaHub.Application.Abstractions; using TarninaHub.Application.Dtos; using TarninaHub.Application.Security; namespace TarninaHub.Controllers; [ApiController] [ApiVersion("1.0")] [Route("api/notifications")] [Authorize] public class NotificationsController : ControllerBase { private readonly INotificationService _notifications; public NotificationsController(INotificationService notifications) { _notifications = notifications; } [HttpGet] public async Task>> List(CancellationToken cancellationToken) { var userId = User.GetUserId(); if (string.IsNullOrWhiteSpace(userId)) { return Unauthorized(); } var notifications = await _notifications.ListForUserAsync(userId, cancellationToken); return Ok(notifications); } [HttpPost("{notificationId}/read")] public async Task> MarkRead( string notificationId, CancellationToken cancellationToken) { var userId = User.GetUserId(); if (string.IsNullOrWhiteSpace(userId)) { return Unauthorized(); } var notification = await _notifications.MarkReadAsync(notificationId, userId, cancellationToken); return notification is null ? NotFound() : Ok(notification); } }