Skip to content

feat(community): enrich feed & post-detail responses#57

Merged
Rashed99Azm merged 1 commit into
develop-backendfrom
feat/enhance-community-models
Jun 14, 2026
Merged

feat(community): enrich feed & post-detail responses#57
Rashed99Azm merged 1 commit into
develop-backendfrom
feat/enhance-community-models

Conversation

@Rashed99Azm

Copy link
Copy Markdown
Collaborator

Summary

  • Enrich feed responseCommunityFeedItemDto now includes DownvoteCount, TopicNameAr/En, IsExpert, IsWatchlisted, and VoteStatus (-1/0/1); all user-specific flags are populated from the current user's JWT and fall back to neutral defaults for anonymous requests
  • Enrich post-detail responseGET /api/community/posts/{id} returns a new PostDetailDto with a nested PostAuthorDto (id, name, avatar, expert flag, posts count, follower count) plus topic names and user-specific flags; handler rewritten as a single JOIN query (one SQL round trip) and aligned with Response<T> + MessageFactory
  • User activity counters — add PostsCount and CommentsCount to the User aggregate (same denormalized pattern as Post); maintained atomically in PublishPost, SoftDeletePost, CreateReply, and SoftDeleteReply handlers; migration AddUserActivityCounters adds both columns as int NOT NULL DEFAULT 0
  • Feed sort & filter — new MostCommented sort option (PostFeedSort = 3); new optional PostType filter (Info/Question/Poll); PostType filter bypasses the Redis fast-path to SQL
  • MessageFactory alignment — migrate GetMyFollows, ListPublicPostReplies, and ListPublicPostsInTopic handlers from raw return types to Response<T>; fix four endpoints that were calling Results.Ok/NotFound manually to use ToHttpResult()

Test plan

  • GET /api/community/feed — anonymous request returns feed with topicNameAr/En, downvoteCount, isExpert, isWatchlisted=false, voteStatus=0
  • GET /api/community/feed with JWT — isWatchlisted and voteStatus reflect the authenticated user's state
  • GET /api/community/feed?sort=3 — results ordered by commentsCount descending
  • GET /api/community/feed?postType=1 — only Question posts returned
  • GET /api/community/posts/{id} — response shape has nested author object, topicNameAr/En, isWatchlisted, voteStatus; 404 returns standard error envelope
  • Publish a post → author's postsCount increments; soft-delete it → decrements
  • Create a reply → author's commentsCount increments; soft-delete the reply → decrements
  • GET /api/community/topics/{slug}, /topics/{id}/posts, /posts/{id}/replies, /api/me/follows — all return standard Response<T> envelope (not raw JSON)

…ty counters

Feed endpoint:
- Add DownvoteCount, TopicNameAr/En, IsExpert, IsWatchlisted, VoteStatus to CommunityFeedItemDto
- Add MostCommented sort (PostFeedSort = 3) ordered by CommentsCount DESC
- Add PostType filter (Info/Question/Poll) to ListCommunityFeedQuery; bypasses Redis fast-path

Get post by id:
- Replace flat author fields with nested PostAuthorDto (Id, Name, AvatarUrl, IsExpert, PostsCount, FollowerCount)
- Add TopicNameAr/En, IsWatchlisted, VoteStatus to PostDetailDto
- Rewrite handler as a single JOIN query (one SQL round trip); align with Response<T> + MessageFactory

User activity counters:
- Add PostsCount and CommentsCount to User domain model with Increment/Decrement methods
- Add EF configuration (DEFAULT 0) and migration AddUserActivityCounters
- Maintain PostsCount in PublishPostCommandHandler and SoftDeletePostCommandHandler
- Maintain CommentsCount in CreateReplyCommandHandler and SoftDeleteReplyCommandHandler

MessageFactory alignment:
- Migrate GetMyFollows, ListPublicPostReplies, ListPublicPostsInTopic handlers to Response<T>
- Fix four endpoints still using manual Results.Ok/NotFound to use ToHttpResult()
@Rashed99Azm Rashed99Azm merged commit f368ec8 into develop-backend Jun 14, 2026
2 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants