40 lines
1.4 KiB
C#
40 lines
1.4 KiB
C#
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<ProblemDetails>(StatusCodes.Status401Unauthorized)]
|
|
public sealed class NotificationsController(NotificationService notifications) : ControllerBase
|
|
{
|
|
[HttpGet]
|
|
public Task<PagedResult<NotificationDto>> 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<UnreadCountDto> CountUnread(CancellationToken ct) => notifications.CountUnreadAsync(ct);
|
|
|
|
[HttpPost("{id:int}/read")]
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
[ProducesResponseType<ProblemDetails>(StatusCodes.Status404NotFound)]
|
|
public async Task<IActionResult> MarkRead(int id, CancellationToken ct)
|
|
{
|
|
await notifications.MarkReadAsync(id, ct);
|
|
return NoContent();
|
|
}
|
|
|
|
[HttpPost("read-all")]
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
public async Task<IActionResult> MarkAllRead(CancellationToken ct)
|
|
{
|
|
await notifications.MarkAllReadAsync(ct);
|
|
return NoContent();
|
|
}
|
|
}
|