2024-10-02 19:23:19 +02:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
using Bit.Core.Context;
|
|
|
|
|
|
using Bit.Core.Exceptions;
|
2024-12-18 15:59:50 +01:00
|
|
|
|
using Bit.Core.Models.Data;
|
2024-10-03 22:13:43 +02:00
|
|
|
|
using Bit.Core.NotificationCenter.Models.Data;
|
2024-10-02 19:23:19 +02:00
|
|
|
|
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;
|
|
|
|
|
|
|
2024-10-03 22:13:43 +02:00
|
|
|
|
public class GetNotificationStatusDetailsForUserQuery : IGetNotificationStatusDetailsForUserQuery
|
2024-10-02 19:23:19 +02:00
|
|
|
|
{
|
|
|
|
|
|
private readonly ICurrentContext _currentContext;
|
|
|
|
|
|
private readonly INotificationRepository _notificationRepository;
|
|
|
|
|
|
|
2024-10-03 22:13:43 +02:00
|
|
|
|
public GetNotificationStatusDetailsForUserQuery(ICurrentContext currentContext,
|
2024-10-02 19:23:19 +02:00
|
|
|
|
INotificationRepository notificationRepository)
|
|
|
|
|
|
{
|
|
|
|
|
|
_currentContext = currentContext;
|
|
|
|
|
|
_notificationRepository = notificationRepository;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-18 15:59:50 +01:00
|
|
|
|
public async Task<PagedResult<NotificationStatusDetails>> GetByUserIdStatusFilterAsync(
|
|
|
|
|
|
NotificationStatusFilter statusFilter, PageOptions pageOptions)
|
2024-10-02 19:23:19 +02:00
|
|
|
|
{
|
|
|
|
|
|
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,
|
2024-12-18 15:59:50 +01:00
|
|
|
|
statusFilter, pageOptions);
|
2024-10-02 19:23:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|