Class NotificationsController
- Namespace
- Builvero.Api.Controllers
- Assembly
- Builvero.Api.dll
Provides API endpoints for user notification management.
[ApiController]
[Route("api/notifications")]
[Authorize]
public class NotificationsController : ControllerBase
- Inheritance
-
NotificationsController
- Inherited Members
Remarks
All endpoints require authentication (JWT token). Users can only access their own notifications. This controller provides:
- Notification summary with unread counts by type
- Retrieval of unread notifications
- Marking individual notifications as read
- Marking all notifications as read
Constructors
NotificationsController(INotificationService)
Initializes a new instance of the NotificationsController class.
public NotificationsController(INotificationService notificationService)
Parameters
notificationServiceINotificationServiceService for notification operations.
Methods
GetNotifications(CancellationToken)
Retrieves all unread notifications for the authenticated user.
[HttpGet]
public Task<ActionResult<List<NotificationDto>>> GetNotifications(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<ActionResult<List<NotificationDto>>>
200 OK: Returns list of NotificationDto objects
400 Bad Request: Error retrieving notifications
Remarks
Requires authentication. Only unread notifications are returned. Each notification includes its type and JSON payload.
GetSummary(CancellationToken)
Retrieves a summary of notifications for the authenticated user, including unread counts by type.
[HttpGet("summary")]
public Task<ActionResult<NotificationSummaryDto>> GetSummary(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<ActionResult<NotificationSummaryDto>>
200 OK: Returns NotificationSummaryDto with unread counts
400 Bad Request: Error retrieving summary
Remarks
Requires authentication. Returns counts for each notification type to enable UI badges and filtering.
MarkAllAsRead(CancellationToken)
Marks all unread notifications as read for the authenticated user.
[HttpPost("mark-all-read")]
public Task<IActionResult> MarkAllAsRead(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<IActionResult>
200 OK: Returns
{ "message": "All notifications marked as read" }400 Bad Request: Error marking notifications as read
Remarks
Requires authentication. This operation is idempotent - calling it multiple times has the same effect.
MarkAsRead(Guid, CancellationToken)
Marks a specific notification as read for the authenticated user.
[HttpPost("{id}/read")]
public Task<IActionResult> MarkAsRead(Guid id, CancellationToken cancellationToken)
Parameters
idGuidThe unique identifier of the notification to mark as read.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<IActionResult>
200 OK: Returns
{ "message": "Notification marked as read" }403 Forbidden: User attempts to mark a notification that doesn't belong to them
400 Bad Request: Notification not found or other error
Remarks
Requires authentication. Users can only mark their own notifications as read.