namespace Brizco.Repository.MartenHandlers.Notifications; public class ReadNotificationCommandHandler(IMartenRepositoryWrapper martenRepositoryWrapper, ICurrentUserService currentUserService) : IRequestHandler { public async Task Handle(ReadNotificationCommand request, CancellationToken cancellationToken) { var notification = await martenRepositoryWrapper.SetRepository() .GetEntityAsync(request.Id, cancellationToken); if (notification == null) throw new BaseApiException(ApiResultStatusCode.NotFound, "Notification not found"); if (!Guid.TryParse(currentUserService.UserId, out Guid userId)) throw new BaseApiException(ApiResultStatusCode.NotFound, "User id is null"); if (notification.UserId != userId) throw new BaseApiException(ApiResultStatusCode.NotFound, "This is not your notification"); notification.IsRead = true; await martenRepositoryWrapper.SetRepository() .AddOrUpdateEntityAsync(notification, cancellationToken); return true; } }