using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using TaskTrackingSystem.Shared; using TaskTrackingSystem.WebApi.Infrastructure; namespace TaskTrackingSystem.WebApi.Features.Notification; [ApiController] [Authorize] [Route("api/[controller]")] public class NotificationController : ControllerBase { private readonly NotificationService _notificationService; public NotificationController(NotificationService notificationService) { _notificationService = notificationService; } [HttpGet("mine")] public async Task>> GetMine([FromQuery] int take = 10) { var userId = User.GetUserId(); if (userId <= 0) { return Unauthorized(); } var items = await _notificationService.GetRecentAsync(userId, take); return Ok(items); } [HttpGet("unread-count")] public async Task> GetUnreadCount() { var userId = User.GetUserId(); if (userId <= 0) { return Unauthorized(); } var count = await _notificationService.GetUnreadCountAsync(userId); return Ok(count); } [HttpPost("{id}/read")] public async Task> MarkRead(long id) { var userId = User.GetUserId(); if (userId <= 0) { return Unauthorized(Result.Failure("User is not authenticated.", 401)); } var result = await _notificationService.MarkReadAsync(userId, id); return StatusCode(result.StatusCode, result); } [HttpDelete("read")] public async Task>> DeleteRead([FromQuery] DateTime? before = null) { var userId = User.GetUserId(); if (userId <= 0) { return Unauthorized(Result.Failure("User is not authenticated.", 401)); } var deletedCount = await _notificationService.DeleteReadNotificationsAsync(userId, before); return Ok(Result.Success(deletedCount)); } }