hngprojects / hng_boilerplate_php_laravel_web

Apache License 2.0
148 stars 58 forks source link

[FEAT]: Implement API Endpoint for Adding Blog Categories #49

Closed Charlesmbuu closed 2 weeks ago

Charlesmbuu commented 1 month ago

Description

Develop backend logic to securely handle adding blog categories by superadmins. The API should allow superadmins to create new categories for organizing blog posts.

Acceptance Criteria

Blog Category Creation

Validation and Sanitization

Data Storage

Response Handling

Purpose

Enhance backend functionality for adding blog categories securely, enabling superadmins to organize blog posts effectively with strict access control enforced via token authentication.

Requirements

Expected Outcome

The backend should securely manage the creation of blog categories, providing reliable functionality for superadmins to organize blog posts effectively with strict access control enforced via token authentication throughout the process.

Endpoint

Create Blog Category

Description: Handles requests to create new blog categories.
Endpoint: POST /api/v1/blog-categories

Request Body:

    {
      "name": "string"
    }

Success Response: Status Code: 201 Created Response Body:

    {
      "status": "success",
      "message": "Blog category created successfully.",
      "data": {
        "name": "Category Name"
      },
      "status_code": 201
    }

Error Responses:

Status Code: 400 Bad Request Response Body:

    {
      "status": "error",
      "message": "Invalid request data. Please provide a valid category name.",
      "status_code": 400
    }

Status Code: 401 Unauthorized (Token Issues) Response Body:

{
  "status": "error",
  "message": "Unauthorized. Token is missing or invalid.",
  "status_code": 401
}

Status Code: 403 Forbidden (Role Issues) Response Body:

{
  "status": "error",
  "message": "Forbidden. You do not have permission to create blog categories.",
  "status_code": 403
}

Status Code: 500 Internal Server Error Response Body:

    {
      "status": "error",
      "message": "Internal Server Error. Please try again later.",
      "status_code": 500
    }

Database Schema:

Table Name: blog_categories

Column Name Data Type Description
id Integer Primary key, auto-generated ID for the category.
name String Name of the blog category.
createdAt Timestamp Timestamp when the category was created.
updatedAt Timestamp Timestamp when the category was last updated.

Tasks

Testing

Dependencies and Impact

Dependencies:

Impact Analysis:

Charlesmbuu commented 1 month ago

This issue is linked to an already approved issue