Spaces:
Running
Running
| using Microsoft.AspNetCore.Authorization; | |
| using Microsoft.AspNetCore.Mvc; | |
| using TaskTrackingSystem.Shared; | |
| using TaskTrackingSystem.WebApi.Infrastructure; | |
| namespace TaskTrackingSystem.WebApi.Features.Notification; | |
| [] | |
| [] | |
| [] | |
| public class NotificationController : ControllerBase | |
| { | |
| private readonly NotificationService _notificationService; | |
| public NotificationController(NotificationService notificationService) | |
| { | |
| _notificationService = notificationService; | |
| } | |
| [] | |
| public async Task<ActionResult<IEnumerable<TaskTrackingSystem.Shared.Models.Notification.NotificationDto>>> GetMine([FromQuery] int take = 10) | |
| { | |
| var userId = User.GetUserId(); | |
| if (userId <= 0) | |
| { | |
| return Unauthorized(); | |
| } | |
| var items = await _notificationService.GetRecentAsync(userId, take); | |
| return Ok(items); | |
| } | |
| [] | |
| public async Task<ActionResult<int>> GetUnreadCount() | |
| { | |
| var userId = User.GetUserId(); | |
| if (userId <= 0) | |
| { | |
| return Unauthorized(); | |
| } | |
| var count = await _notificationService.GetUnreadCountAsync(userId); | |
| return Ok(count); | |
| } | |
| [] | |
| public async Task<ActionResult<Result>> 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); | |
| } | |
| [] | |
| public async Task<ActionResult<Result<int>>> 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<int>.Success(deletedCount)); | |
| } | |
| } | |