Class NotificationService
- Namespace
- Builvero.Application.Services
- Assembly
- Builvero.Application.dll
Provides business logic for user notification management including retrieval, marking as read, and summary statistics.
public class NotificationService : INotificationService
- Inheritance
-
NotificationService
- Implements
- Inherited Members
Remarks
This service handles all notification-related operations:
- Retrieving notification summaries (unread counts)
- Retrieving unread notifications with type-specific payloads
- Marking individual notifications as read
- Marking all notifications as read for a user
Constructors
NotificationService(IUserNotificationRepository)
Initializes a new instance of the NotificationService class.
public NotificationService(IUserNotificationRepository notificationRepository)
Parameters
notificationRepositoryIUserNotificationRepositoryRepository for notification data access operations.
Methods
GetNotificationsAsync(Guid, CancellationToken)
Retrieves all unread notifications for a user.
public Task<List<NotificationDto>> GetNotificationsAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user whose notifications should be retrieved.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<List<NotificationDto>>
A list of NotificationDto objects representing unread notifications.
Remarks
Only unread notifications are returned. Each notification includes its type and JSON payload containing type-specific data (e.g., project details, sender information).
GetSummaryAsync(Guid, CancellationToken)
Retrieves a summary of notifications for a user, including unread counts by notification type.
public Task<NotificationSummaryDto> GetSummaryAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user whose notification summary should be retrieved.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<NotificationSummaryDto>
A NotificationSummaryDto containing unread counts by notification type.
Remarks
The summary includes counts for each notification type (e.g., ProjectInvitationReceived, ProjectJoinRequestReceived) to enable UI badges and filtering.
MarkAllAsReadAsync(Guid, CancellationToken)
Marks all unread notifications as read for a user.
public Task MarkAllAsReadAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user whose notifications should be marked as read.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task
- Provides business logic for user notification management including retrieval, marking as read, and summary statistics.
Remarks
This operation is idempotent - calling it multiple times has the same effect. All unread notifications for the user are updated in a single database operation for efficiency.
MarkAsReadAsync(Guid, Guid, CancellationToken)
Marks a specific notification as read for a user.
public Task MarkAsReadAsync(Guid notificationId, Guid userId, CancellationToken cancellationToken = default)
Parameters
notificationIdGuidThe unique identifier of the notification to mark as read.
userIdGuidThe unique identifier of the user marking the notification as read.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task
- Provides business logic for user notification management including retrieval, marking as read, and summary statistics.
Remarks
Users can only mark their own notifications as read. This is enforced by checking that the notification's
UserId matches the provided userId.
Exceptions
- Exception
Thrown when the notification is not found.
- UnauthorizedAccessException
Thrown when the user attempts to mark a notification that doesn't belong to them.