namespace Brizco.Repository.MartenHandlers.Notifications; public class GetNotificationsCountQueryHandler(IMartenRepositoryWrapper martenRepositoryWrapper,ICurrentUserService currentUserService) : IRequestHandler { public async Task Handle(GetNotificationsCountQuery request, CancellationToken cancellationToken) { if (currentUserService.ComplexId == null) throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is null"); if (!Guid.TryParse(currentUserService.ComplexId, out Guid complexId)) throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is wrong"); Guid userId; if (currentUserService.UserId == null) throw new BaseApiException(ApiResultStatusCode.BadRequest, "User id is null"); if (!Guid.TryParse(currentUserService.UserId, out userId)) throw new BaseApiException(ApiResultStatusCode.BadRequest, "User id is wrong"); var notifications = await martenRepositoryWrapper.SetRepository() .GetEntitiesAsync(n => n.ComplexId == complexId && n.UserId == userId && !n.IsRead, cancellationToken); return notifications.Count; } }