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

Add products (main dashboard) #218

Open
AlakaTahir opened this issue Aug 6, 2024 · 0 comments
Open

Add products (main dashboard) #218

AlakaTahir opened this issue Aug 6, 2024 · 0 comments

Comments

@AlakaTahir
Copy link
Contributor

Description
Implement a backend feature to allow the creation of new multiple product at a time in the database. This endpoint will facilitate adding new products with details such as name, description, price, and category.

Acceptance Criteria
A POST endpoint is available at /api/v1/products/add-products.
The endpoint successfully creates list of new products and stores it in the database.
Appropriate HTTP status codes are returned (e.g., 201 Created for success, 400 Bad Request for invalid input).
Ensure validation of input data to prevent malformed or incomplete product entries.
Purpose
Provide an API endpoint for creating new products to facilitate the addition of products to the system.

Requirements
Create a backend endpoint to handle products creation requests.
Validate input data to ensure all necessary fields are provided and correctly formatted.
Ensure proper error handling and response statuses.
Update any related data or references accordingly.

Data validation
Input Validation:

Ensure all necessary fields (e.g., name, description, price, category) are provided and correctly formatted.

Validate that price is a positive number.

Output Validation:

Verify that the response includes the created product's details with correct data types.
Authentication and Authorization
Authentication:

Ensure the endpoint requires user authentication to create products.
Authorization:

Implement role-based access control to ensure only authorized users can create products.
Expected Outcome
A POST endpoint at /api/v1/products/add-products that:

Accepts product data (e.g., name, description, price, category, etc.).
Validates the input data.
Inserts the new product into the database.
Returns a 201 Created status with the created product details.
Returns appropriate error messages and statuses for invalid input or server errors.
Successful Response (201 Created):
{
"status": "success",
"message": "Products created successfully",
"data": [{
"id": 123,
"name": "New Product",
"description": "A description of the new product.",
"price": 29.99,
"category": "Electronics",
"created_at": "2024-07-17",
"updated_at": "2024-07-17"
}]
}
Error Response (400 Bad Request):
{
"status_code": 400,
"status": "Bad request",
"message": "Invalid input data",
"errors": {
"name": "Name is required",
"price": "Price must be a positive number"
}
}
Error Response (401 Unauthorized)
{
"status_code": 401,
"status": "unauthorized",
"message": "Unauthorized. Please log in."
}
Error Response (500 Internal Server Error):
{
"status_code": 500,
"status": "Internal server error",
"message": "An unexpected error occurred. Please try again later."
}
Testing Requirements
Unit Tests:

Verify the need for unit tests to cover all functionality of the endpoint.
Integration Tests:

Confirm the requirement for integration tests to ensure the endpoint works correctly with the overall system.

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 a pull request may close this issue.

1 participant