Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Adding a threading (nested comments) feature to the comment module #1328

Open
canonone opened this issue Mar 1, 2025 · 0 comments
Open
Labels

Comments

@canonone
Copy link

canonone commented Mar 1, 2025

Description

Add a threading (nested comments) feature to the comment module, allowing users and admins to reply to specific comments, creating a hierarchical conversation structure. This will enable replies to be linked to a parent comment, improving discussion clarity and organization.

Acceptance Criteria

  • Users can create a top-level comment without specifying a parentId.

  • Users can create a reply to an existing comment by providing a valid parentId in the POST /comments/add request.

  • A new endpoint GET /comments/:id/thread returns a comment with its nested replies, including user details for each.

  • The database schema supports threading with a parent_id column in the comments table.

  • Validation ensures parentId is a valid UUID (v4) when provided, and it’s optional for top-level comments.

  • Error handling returns appropriate HTTP status codes (e.g., 404 for invalid parentId, 400 for empty comments).

Purpose

This feature is needed to enhance the comment system by allowing structured conversations, making it easier for admins to respond directly to user comments for clarification or follow-up. It improves user experience and aligns the system with common discussion patterns seen in platforms like Reddit or X.

Requirements

Expected Outcome

  • A user can post a comment: POST /comments/add with { "model_id": "prod1", "model_type": "product", "comment": "Great product!" }, resulting in a top-level comment.

  • An admin can reply: POST /comments/add with { "model_id": "prod1", "model_type": "product", "comment": "Thanks! Why?", "parentId": "" }, creating a nested reply.

  • Fetching GET /comments//thread returns a JSON object like:

{
  "message": "Comment thread retrieved successfully",
  "data": {
    "id": "<comment-id>",
    "comment": "Great product!",
    "user": { "id": "user1", "first_name": "Jane", "last_name": "Doe" },
    "replies": [
      {
        "id": "<reply-id>",
        "comment": "Thanks! Why?",
        "user": { "id": "user2", "first_name": "John", "last_name": "Smith" },
        "replies": []
      }
    ]
  }
}

The database reflects the hierarchy with parent_id linking replies to their parent comments.

Additional Context

  • Current State: The comment module supports flat comments only (POST /comments/add and GET /comments/:id). Threading is not implemented.

  • Database: Using PostgreSQL, so the parent_id column must be added via a migration (e.g., ALTER TABLE comments ADD COLUMN parent_id UUID REFERENCES comments(id)).

  • Handoff: The application code is ready, but the PostgreSQL schema update is TBD by the database team.

  • Use Case: Admins need to reply directly to user comments for clarification, which flat comments don’t support effectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant