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: Implement Task Commenting Feature #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ShubhamAggarwal0812
Copy link
Owner

Pull Request for Task Commenting Feature

Description

This PR introduces the task commenting feature to our application. Users can now add, edit, delete, and view comments on tasks. The implementation includes both backend and frontend changes to support this functionality.

Why is this change needed?

This change is necessary to allow users to communicate and collaborate on tasks by adding comments. It enhances the task management system by enabling better communication and feedback.

Changes Overview

Backend

  1. New Endpoints:

    • POST /comments: Create a new comment for a task.
    • GET /comments/:taskId: Fetch all comments for a specific task.
    • PUT /comments/:commentId: Update a specific comment.
    • DELETE /comments/:commentId: Delete a specific comment.
  2. Database Models:

    • CommentDB Schema: Defines the structure of comments stored in the database.
  3. Controllers:

    • CommentController: Handles the HTTP requests for comments.
  4. Services:

    • CommentService: Contains the business logic for managing comments.
  5. Utils:

    • CommentUtil: Converts database objects to API responses.

Frontend

  1. Components:

    • CommentList: Displays a list of comments for a task.
    • AddComment: Allows users to add a new comment to a task.
  2. Context:

    • CommentContext: Manages the state and actions related to comments.
  3. Services:

    • CommentService: Handles API calls related to comments.
  4. Types:

    • Comment: Defines the structure of comment objects used in the frontend.

API Changes

  • POST /comments

    • Request Body:
      {
        "taskId": "string",
        "comment": "string"
      }
    • Response:
      {
        "id": "string",
        "task": "string",
        "account": {
          "id": "string",
          "firstName": "string",
          "lastName": "string",
          "username": "string"
        },
        "comment": "string",
        "createdAt": "string",
        "updatedAt": "string"
      }
  • GET /comments/:taskId

    • Response:
      [
        {
          "id": "string",
          "task": "string",
          "account": {
            "id": "string",
            "firstName": "string",
            "lastName": "string",
            "username": "string"
          },
          "comment": "string",
          "createdAt": "string",
          "updatedAt": "string"
        }
      ]
  • PUT /comments/:commentId

    • Request Body:
      {
        "taskId": "string",
        "comment": "string"
      }
    • Response:
      {
        "id": "string",
        "task": "string",
        "account": {
          "id": "string",
          "firstName": "string",
          "lastName": "string",
          "username": "string"
        },
        "comment": "string",
        "createdAt": "string",
        "updatedAt": "string"
      }
  • DELETE /comments/:commentId

    • Response: 204 No Content

Database Schema Changes

No changes were made to the existing database schema. The new CommentDB schema was added to support comments.

Tests

Automated Test Cases Added: (Yet to add)

  1. Creating a Comment: Validates that a comment can be created successfully.
  2. Fetching Comments for a Task: Ensures that comments for a task are fetched correctly.
  3. Updating a Comment: Checks that a comment can be updated.
  4. Deleting a Comment: Confirms that a comment can be deleted.

Manual Test Cases Run:

  1. Creating a Comment:
    • Navigate to a task.
    • Add a comment.
    • Verify that the comment appears in the list.
  2. Fetching Comments for a Task:
    • Refresh the task page.
    • Ensure that all comments are displayed correctly.
  3. Updating a Comment:
    • Edit an existing comment.
    • Verify that the changes are saved and displayed.
  4. Deleting a Comment:
    • Delete a comment.
    • Confirm that the comment is removed from the list.

Meta Information

Self Review

This PR has been self-reviewed to ensure quality and consistency.

Thank you for reviewing this PR.

@ShubhamAggarwal0812 ShubhamAggarwal0812 self-assigned this Jul 5, 2024
@ShubhamAggarwal0812
Copy link
Owner Author

PR Update: Implementations Based on Feedback

I have refactored both the backend and frontend code for the commenting feature as per the feedback provided. Below are the changes made:

Backend

  1. Updated Comment Util:

    • Refactored convertCommentDBToComment to handle both ObjectId and Account types for comment.account.
  2. Comment Types:

    • Replaced the use of any with proper types for comment.account.
    • Removed the non-null assertion operator (!) for better type safety.
  3. Soft Deletion:

    • Added an active field in the CommentDB schema to support soft deletion.
    • Updated the deleteComment method to perform soft deletion by setting active to false.
  4. Comment Router and Server:

    • Adjusted the routing structure to use /tasks/:taskId/comments for all comment-related operations.
    • Ensured consistency in endpoints for creating, updating, deleting, and fetching comments.
  5. Comment Serializer:

    • Modified the serializer to handle both string and Account types for comment.account.

Frontend

  1. Comment Provider:

    • Updated context functions to match the new backend endpoints.
    • Adjusted the deleteComment function to include the taskId parameter.
  2. Comment List Component:

    • Refactored to properly handle the new account structure.
    • Ensured proper display of account details in the comment section.
  3. Comment Service:

    • Updated API service methods to match the new endpoint structure for comments under tasks.

These changes ensure proper integration between the frontend and backend while adhering to the feedback provided. The code has been tested to confirm that it works as expected.

Please review the updates and let me know if there are any further changes required.

task: comment.task,
account:
typeof comment.account === 'string'
? { id: comment.account }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if an account is a string then just do comment. account no need for an id field inside the object.

this.comment = comment;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need this constructor?

}

private static convertAccount(
account: Types.ObjectId | Account,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convertPopulatedAccountDBToAccount(
account: Types.ObjectId | Account,
): string | Account

@aniketrathi
Copy link

Write automated test cases

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