API Endpoints

The backend provides the following endpoints for managing categories:

Fetch Categories

  • Endpoint: GET /categories
  • Description: Retrieves the list of all categories.
  • Response:
    [
      {
        "_id": "category-id",
        "name": "Technology",
        "description": "Posts related to technology",
        "parent": null
      }
    ]
    

Create Category

  • Endpoint: POST /categories
  • Description: Creates a new category.
  • Request Body:
    {
      "name": "Business",
      "description": "Business-related posts",
      "parent": "parent-category-id"
    }
    

Update Category

  • Endpoint: PUT /categories/{id}
  • Description: Updates an existing category.
  • Request Body:
    {
      "name": "Updated Name",
      "description": "Updated description"
    }
    

Delete Category

  • Endpoint: DELETE /categories/{id}
  • Description: Deletes a category and reassigns related blog posts.

Auto-Generated Categories from User Tags

  • Users can assign tags to blog posts.
  • If a tag matches an existing category, it is linked automatically.
  • If a tag does not match any existing category, it is grouped under Other.
  • Administrators can later create a proper category and reassign posts.

Frontend Implementation

In the blog creation form, users can select an existing category or enter a new tag. The system processes the input and either assigns it to an existing category or places it under Other.

{categories.map((category) => (
  <option key={category._id} value={category._id}>{category.name}</option>
))}

Conclusion

The category management system ensures efficient content organization and user-friendly navigation. Administrators maintain control over available categories, while users contribute dynamically through tags.