hngprojects / hng_boilerplate_nestjs

Description
Apache License 2.0
182 stars 105 forks source link

[FEAT] COMMENT FUNCTIONALITY - BACKEND #151

Closed samsmithKruz closed 2 weeks ago

samsmithKruz commented 1 month ago

Description

Implement a feature that allows users to add comments to individual posts.

Acceptance Criteria

  1. Database Schema

    • Design and create a database schema for storing comments.
    • Ensure the schema links comments to respective contents using the model name.
  2. API Endpoints

    • Create an endpoint to add a new comment accessible at /api/v1/comments/add.
    • The endpoint should accept POST requests to receive comment data.
    • Given a POST request with comment data, the system should validate and sanitize the incoming data.
  3. Validation Rules

    • Required fields: item_id, model_name, comment.
    • comment should be a non-empty string.
    • item_id and model_name should be valid IDs and model name (table) referencing existing contents and users.
  4. Database Storage

    • Given valid comment data, the endpoint should securely store the information in the database.
  5. Error Handling

    • The system should handle errors gracefully and return appropriate status codes.

Request Header

  {
      "Authorization": "Bearer your_jwt_token_here"
  }

Request Body

{
  "item_id": 123,
  "model_name": "Blog | content | post",
  "comment": "This is a comment."
}

Successful Response (status code: 201)

{
  "message": "Comment added successfully!"
}

Error Response

{
  "message": "Invalid input data",
  "status_code": 400,
  "error": "Bad Request"
}

Purpose

To enhance user engagement by allowing interaction through comments.

Requirements

Expected Outcome

Testing

Checklist

markessien commented 1 month ago

Comments are to be generic and attachable to any model

samsmithKruz commented 1 month ago

Alright sir, I've updated the schema such that comments are now generic, the model or schema to which the comment is made will be passed in the "Request Body" as model_name

MuthoniMN commented 1 month ago

@highb33kay @Ameenah-Ameenah @highb33kay @prondubuisi

Please approve this ticket. Thank you