mirror of
https://github.com/bitwarden/server.git
synced 2026-02-05 08:33:10 +08:00
[PM-11123] Service layer for Notification Center (#4741)
* PM-11123: Service layer * PM-11123: Service layer for Notification Center * PM-11123: Throw error on unsupported requirement * PM-11123: Missing await * PM-11123: Cleanup * PM-11123: Unit Test coverage * PM-11123: Flipping the authorization logic to be exact match of fail, formatting * PM-11123: Async warning * PM-11123: Using AuthorizeOrThrowAsync, removal of redundant set new id * PM-11123: UT typo * PM-11123: UT fix
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
#nullable enable
|
||||
using Bit.Core.Context;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.NotificationCenter.Entities;
|
||||
using Bit.Core.NotificationCenter.Models.Filter;
|
||||
using Bit.Core.NotificationCenter.Queries.Interfaces;
|
||||
using Bit.Core.NotificationCenter.Repositories;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
namespace Bit.Core.NotificationCenter.Queries;
|
||||
|
||||
public class GetNotificationsForUserQuery : IGetNotificationsForUserQuery
|
||||
{
|
||||
private readonly ICurrentContext _currentContext;
|
||||
private readonly INotificationRepository _notificationRepository;
|
||||
|
||||
public GetNotificationsForUserQuery(ICurrentContext currentContext,
|
||||
INotificationRepository notificationRepository)
|
||||
{
|
||||
_currentContext = currentContext;
|
||||
_notificationRepository = notificationRepository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Notification>> GetByUserIdStatusFilterAsync(NotificationStatusFilter statusFilter)
|
||||
{
|
||||
if (!_currentContext.UserId.HasValue)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var clientType = DeviceTypes.ToClientType(_currentContext.DeviceType);
|
||||
|
||||
// Note: only returns the user's notifications - no authorization check needed
|
||||
return await _notificationRepository.GetByUserIdAndStatusAsync(_currentContext.UserId.Value, clientType,
|
||||
statusFilter);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user