Class UserNotificationRepository
- Namespace
- Builvero.Infrastructure.Repositories
- Assembly
- Builvero.Infrastructure.dll
Repository implementation for user notification data access operations using Entity Framework Core.
public class UserNotificationRepository : IUserNotificationRepository
- Inheritance
-
UserNotificationRepository
- Implements
- Inherited Members
Remarks
User notifications inform users about events such as project invitations, join requests, and their outcomes. Notifications can be marked as read/unread and support various notification types.
Constructors
UserNotificationRepository(ApplicationDbContext)
Initializes a new instance of the UserNotificationRepository class.
public UserNotificationRepository(ApplicationDbContext context)
Parameters
contextApplicationDbContextThe Entity Framework database context for data access.
Methods
CreateAsync(UserNotification, CancellationToken)
Creates a new user notification in the database.
public Task<UserNotification> CreateAsync(UserNotification notification, CancellationToken cancellationToken = default)
Parameters
notificationUserNotificationThe user notification entity to create.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<UserNotification>
The created user notification entity with its generated ID.
GetByIdAsync(Guid, CancellationToken)
Retrieves a user notification by its unique identifier.
public Task<UserNotification?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default)
Parameters
idGuidThe unique identifier of the notification to retrieve.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<UserNotification>
The user notification if found; otherwise, null.
GetNotificationSummaryAsync(Guid, CancellationToken)
Gets a summary of unread notifications for a user, grouped by notification type.
public Task<NotificationSummaryDto> GetNotificationSummaryAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<NotificationSummaryDto>
A notification summary DTO containing total unread count and counts by notification type.
GetUnreadNotificationsAsync(Guid, CancellationToken)
Retrieves all unread notifications for a user.
public Task<List<UserNotification>> GetUnreadNotificationsAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<List<UserNotification>>
A list of unread notifications, ordered by creation date (newest first).
MarkAllAsReadAsync(Guid, CancellationToken)
Marks all unread notifications for a user as read.
public Task MarkAllAsReadAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe unique identifier of the user.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task
- Repository implementation for user notification data access operations using Entity Framework Core.
UpdateAsync(UserNotification, CancellationToken)
Updates an existing user notification in the database.
public Task UpdateAsync(UserNotification notification, CancellationToken cancellationToken = default)
Parameters
notificationUserNotificationThe user notification entity to update.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task
- Repository implementation for user notification data access operations using Entity Framework Core.