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]: Update a Product by Id #347

Open
17 tasks
Kvngstar opened this issue Jul 27, 2024 · 0 comments
Open
17 tasks

[FEAT]: Update a Product by Id #347

Kvngstar opened this issue Jul 27, 2024 · 0 comments
Labels

Comments

@Kvngstar
Copy link
Contributor

Description

Implement an API endpoint to update a product by its ID.

Acceptance Criteria

  • The endpoint should update the product information based on the provided product ID.
  • The request body should allow updating the product name, description, price, quantity, and category.
  • The endpoint should handle cases where the product is not found.
  • Proper error handling should be implemented for invalid requests.
  • The response should return the updated product information.

Purpose

The purpose of this endpoint is to allow users to update the details of a specific product by its ID.

Requirement

  • The endpoint should be a PUT request to /api/v1/products/{product_id}.
  • The request body should contain the following fields:
  • name (string)
  • description (string)
  • price (number)
  • category (string)
  • quantity (number)
  • The endpoint should validate the product ID.
  • If the product is not found, the response should return a 404 Not Found status.
  • If the product is successfully updated, the response should return a 200 OK status with the updated product information.
  • Appropriate status codes should be returned for successful (200 OK) and unsuccessful requests 404 Not Found, 500 Internal Server Error).

Request Example

PUT /api/v1/products/123

{
  "name": "Updated Product Name",
  "description": "Updated description of the product",
  "price": 20,
  "category": "Electronics",
  "quantity": 100
}

Successful Response

{
  "status": "Success",
  "message": "Product updated successfully",
  "status_code": 200,
  "data": {
    "id": 123,
    "name": "Updated Product Name",
    "description": "Updated description of the product",
    "price": 20,
    "quantity": 100,
    "category": "Electronics"
  }
}

Unsuccessful Response

  • Product Not Found
{
  "status": "Not Found",
  "message": "Product not found",
  "status_code": 404
}
  • Internal Server Error
{
  "status": "An unexpected error occurred",
  "message": "Internal server error",
  "status_code": 500
}

Unit Tests

  • Test updating a product with valid data.
  • Test updating a product that does not exist.
  • Test error handling for unexpected issues during the update process.

Expected Outcome

  • The endpoint successfully updates the product information.
  • The endpoint returns the updated product information in the response.
  • The endpoint returns appropriate error messages and status codes for unsuccessful requests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants