using Helpdesk.Application.Common; using Helpdesk.Application.Notifications; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace Helpdesk.Api.Controllers; [ApiController] [Authorize] [Route("api/notifications")] [ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] public sealed class NotificationsController(NotificationService notifications) : ControllerBase { [HttpGet] public Task> List( [FromQuery] bool unreadOnly = false, [FromQuery] int page = 1, [FromQuery] int pageSize = 20, CancellationToken ct = default) => notifications.ListAsync(unreadOnly, page, pageSize, ct); [HttpGet("unread-count")] public Task CountUnread(CancellationToken ct) => notifications.CountUnreadAsync(ct); [HttpPost("{id:int}/read")] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task MarkRead(int id, CancellationToken ct) { await notifications.MarkReadAsync(id, ct); return NoContent(); } [HttpPost("read-all")] [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task MarkAllRead(CancellationToken ct) { await notifications.MarkAllReadAsync(ct); return NoContent(); } }