diff --git a/backend/src/CCE.Api.Common/Middleware/ExceptionHandlingMiddleware.cs b/backend/src/CCE.Api.Common/Middleware/ExceptionHandlingMiddleware.cs index 354e17b3..8db6270f 100644 --- a/backend/src/CCE.Api.Common/Middleware/ExceptionHandlingMiddleware.cs +++ b/backend/src/CCE.Api.Common/Middleware/ExceptionHandlingMiddleware.cs @@ -45,6 +45,7 @@ await WriteErrorAsync(context, StatusCodes.Status409Conflict, } catch (DomainException ex) { + _logger.LogWarning(ex, "Domain exception: {DomainMessage}", ex.Message); await WriteErrorAsync(context, StatusCodes.Status400BadRequest, "BAD_REQUEST", MessageType.BusinessRule, ex.Message).ConfigureAwait(false); } diff --git a/backend/src/CCE.Application/Community/Public/Queries/ListPublicTopicsPaginated/ListPublicTopicsPaginatedQueryHandler.cs b/backend/src/CCE.Application/Community/Public/Queries/ListPublicTopicsPaginated/ListPublicTopicsPaginatedQueryHandler.cs index 646ee6e6..164e77f2 100644 --- a/backend/src/CCE.Application/Community/Public/Queries/ListPublicTopicsPaginated/ListPublicTopicsPaginatedQueryHandler.cs +++ b/backend/src/CCE.Application/Community/Public/Queries/ListPublicTopicsPaginated/ListPublicTopicsPaginatedQueryHandler.cs @@ -27,10 +27,14 @@ public async Task>> Handle( if (request.SortBy == TopicsSortBy.PostsCount) { - var postCounts = await _db.Posts - .Where(p => p.Status == PostStatus.Published) - .GroupBy(p => p.TopicId) - .Select(g => new { TopicId = g.Key, Count = g.Count() }) + var postCounts = await ( + from p in _db.Posts + join c in _db.Communities on p.CommunityId equals c.Id + where p.Status == PostStatus.Published + && c.IsActive + && c.Visibility == CommunityVisibility.Public + group p by p.TopicId into g + select new { TopicId = g.Key, Count = g.Count() }) .ToListAsyncEither(ct) .ConfigureAwait(false); @@ -102,10 +106,15 @@ public async Task>> Handle( var pagedTopicMap = pagedTopics.ToDictionary(t => t.Id); - var pagedPostCounts = await _db.Posts - .Where(p => topicIds.Contains(p.TopicId) && p.Status == PostStatus.Published) - .GroupBy(p => p.TopicId) - .Select(g => new { TopicId = g.Key, Count = g.Count() }) + var pagedPostCounts = await ( + from p in _db.Posts + join c in _db.Communities on p.CommunityId equals c.Id + where topicIds.Contains(p.TopicId) + && p.Status == PostStatus.Published + && c.IsActive + && c.Visibility == CommunityVisibility.Public + group p by p.TopicId into g + select new { TopicId = g.Key, Count = g.Count() }) .ToListAsyncEither(ct) .ConfigureAwait(false);