51 lines
1.4 KiB
C#
51 lines
1.4 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using MilliSim.Common.Dtos;
|
|
using MilliSim.Common.Models;
|
|
using MilliSim.Services;
|
|
|
|
namespace MilliSim.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/notifications")]
|
|
[Authorize]
|
|
public class NotificationsController : ControllerBase
|
|
{
|
|
private readonly INotificationService _notificationService;
|
|
|
|
public NotificationsController(INotificationService notificationService)
|
|
{
|
|
_notificationService = notificationService;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<ApiResponse<PagedResult<NotificationDto>>> GetNotifications([FromQuery] NotificationType? type, [FromQuery] PageRequest request)
|
|
{
|
|
return await _notificationService.GetNotificationsAsync(type, request);
|
|
}
|
|
|
|
[HttpGet("unread-count")]
|
|
public async Task<ApiResponse<int>> GetUnreadCount()
|
|
{
|
|
return await _notificationService.GetUnreadCountAsync();
|
|
}
|
|
|
|
[HttpPost("{id}/read")]
|
|
public async Task<ApiResponse> MarkAsRead(long id)
|
|
{
|
|
return await _notificationService.MarkAsReadAsync(id);
|
|
}
|
|
|
|
[HttpPost("read-all")]
|
|
public async Task<ApiResponse> MarkAllAsRead()
|
|
{
|
|
return await _notificationService.MarkAllAsReadAsync();
|
|
}
|
|
|
|
[HttpPost("{id}/delete")]
|
|
public async Task<ApiResponse> DeleteNotification(long id)
|
|
{
|
|
return await _notificationService.DeleteNotificationAsync(id);
|
|
}
|
|
}
|