Api/Brizco.Repository/MartenHandlers/Notifications/ReadNotificationCommandHand...

28 lines
1.2 KiB
C#

using Brizco.Domain.MartenEntities.Notifications;
namespace Brizco.Repository.MartenHandlers.Notifications;
public class ReadNotificationCommandHandler : IRequestHandler<ReadNotificationCommand, bool>
{
private readonly IMartenRepositoryWrapper _martenRepositoryWrapper;
private readonly ICurrentUserService _currentUserService;
public ReadNotificationCommandHandler(IMartenRepositoryWrapper martenRepositoryWrapper, ICurrentUserService currentUserService)
{
_martenRepositoryWrapper = martenRepositoryWrapper;
_currentUserService = currentUserService;
}
public async Task<bool> Handle(ReadNotificationCommand request, CancellationToken cancellationToken)
{
var notification = await _martenRepositoryWrapper.SetRepository<Notification>()
.GetEntityAsync(request.Id, cancellationToken);
if (notification == null)
throw new BaseApiException(ApiResultStatusCode.NotFound,"Notification not found");
notification.IsRead = true;
await _martenRepositoryWrapper.SetRepository<Notification>()
.AddOrUpdateEntityAsync(notification, cancellationToken);
return true;
}
}