2024-10-02 19:23:19 +02:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
using Bit.Core.Context;
|
|
|
|
|
|
using Bit.Core.Exceptions;
|
|
|
|
|
|
using Bit.Core.NotificationCenter.Authorization;
|
|
|
|
|
|
using Bit.Core.NotificationCenter.Commands.Interfaces;
|
|
|
|
|
|
using Bit.Core.NotificationCenter.Entities;
|
|
|
|
|
|
using Bit.Core.NotificationCenter.Repositories;
|
2024-11-21 21:39:28 +00:00
|
|
|
|
using Bit.Core.Services;
|
2024-10-02 19:23:19 +02:00
|
|
|
|
using Bit.Core.Utilities;
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Bit.Core.NotificationCenter.Commands;
|
|
|
|
|
|
|
|
|
|
|
|
public class UpdateNotificationCommand : IUpdateNotificationCommand
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly ICurrentContext _currentContext;
|
|
|
|
|
|
private readonly IAuthorizationService _authorizationService;
|
|
|
|
|
|
private readonly INotificationRepository _notificationRepository;
|
2024-11-21 21:39:28 +00:00
|
|
|
|
private readonly IPushNotificationService _pushNotificationService;
|
2024-10-02 19:23:19 +02:00
|
|
|
|
|
|
|
|
|
|
public UpdateNotificationCommand(ICurrentContext currentContext,
|
|
|
|
|
|
IAuthorizationService authorizationService,
|
2024-11-21 21:39:28 +00:00
|
|
|
|
INotificationRepository notificationRepository,
|
|
|
|
|
|
IPushNotificationService pushNotificationService)
|
2024-10-02 19:23:19 +02:00
|
|
|
|
{
|
|
|
|
|
|
_currentContext = currentContext;
|
|
|
|
|
|
_authorizationService = authorizationService;
|
|
|
|
|
|
_notificationRepository = notificationRepository;
|
2024-11-21 21:39:28 +00:00
|
|
|
|
_pushNotificationService = pushNotificationService;
|
2024-10-02 19:23:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task UpdateAsync(Notification notificationToUpdate)
|
|
|
|
|
|
{
|
|
|
|
|
|
var notification = await _notificationRepository.GetByIdAsync(notificationToUpdate.Id);
|
|
|
|
|
|
if (notification == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotFoundException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await _authorizationService.AuthorizeOrThrowAsync(_currentContext.HttpContext.User,
|
|
|
|
|
|
notification, NotificationOperations.Update);
|
|
|
|
|
|
|
|
|
|
|
|
notification.Priority = notificationToUpdate.Priority;
|
|
|
|
|
|
notification.ClientType = notificationToUpdate.ClientType;
|
|
|
|
|
|
notification.Title = notificationToUpdate.Title;
|
|
|
|
|
|
notification.Body = notificationToUpdate.Body;
|
|
|
|
|
|
notification.RevisionDate = DateTime.UtcNow;
|
|
|
|
|
|
|
|
|
|
|
|
await _notificationRepository.ReplaceAsync(notification);
|
2024-11-21 21:39:28 +00:00
|
|
|
|
|
2024-11-26 16:04:43 +00:00
|
|
|
|
await _pushNotificationService.PushNotificationAsync(notification);
|
2024-10-02 19:23:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|