Products Service - Representation of the products for a catalog where merchants can add updates and display products.
This project the code for Product service. The /service
folder contains the models.py
file for Product model and a routes.py
file for Product service. The /tests
folder has test case for testing the model and the service separately.
Before Run, make sure you have install Docker Desktop, Visual Studio Code, Remote Containers extension first. Then you could clone the repository and then run the following commands:
cd products
code .
- Reopen the folder in Dev Container
- Run
flask run
command on the terminal - The service is available at localhost:
http://localhost:8000
To run the all the test cases locally, please run the command nosetests. The test cases have 96% code coverage currently.
GET /
Endpoint | Methods | Rule |
---|---|---|
create_products | POST | /products |
delete_products | DELETE | /products/{int:product_id} |
get_products | GET | /products/{int:product_id} |
list_products | GET | /products |
update_products | PUT | /products/{int:product_id} |
URL : http://127.0.0.1:8000/products
Method : POST
Auth required : No
Permissions required : None
Create a product with json file which included product name, description, price, category, inventory, discount and created date.
Example:
Request Body (JSON)
{
"price": 0.5,
"name": "Cheese",
"category": "dairy",
"created_date": "2023-03-07",
"inventory": 5,
"desc": "This is more popular",
"discount": 1
}
Success Response : HTTP_201_CREATED
{
"category": "dairy",
"created_date": "2023-03-07",
"deleted_date": null,
"desc": "This is more popular",
"discount": 1.0,
"id": 956,
"inventory": 5,
"modified_date": null,
"name": "Cheese",
"price": 0.5
}
URL : http://127.0.0.1:8000/products/{int:product_id}
Method : GET
Auth required : No
Permissions required : None
Gets/Reads a product with id provided in the URL
Example:
Success Response : HTTP_200_OK
{
"category": "dairy",
"created_date": "2023-03-07",
"deleted_date": null,
"desc": "This is more popular",
"discount": 1.0,
"id": 956,
"inventory": 5,
"modified_date": null,
"name": "Cheese",
"price": 0.5
}
Failure Response : HTTP_404_NOT_FOUND
{
"error": "Not Found",
"message": "404 Not Found: Product with id '1' could not be found.",
"status": 404
}
URL : http://127.0.0.1:8000/products/{int:product_id}
Method : PUT
Auth required : No
Permissions required : None
Updates a product with id provided in the URL according to the updated fields provided in the body
Example:
Request Body (JSON)
{
"price": 0.5,
"name": "Cheese",
"category": "dairy",
"created_date": "2023-03-07",
"inventory": 50,
"desc": "This is more popular",
"discount": 1
}
Success Response : HTTP_200_OK
{
"category": "dairy",
"created_date": "2023-03-07",
"deleted_date": null,
"desc": "This is more popular",
"discount": 1.0,
"id": 955,
"inventory": 50,
"modified_date": null,
"name": "Cheese",
"price": 0.5
}
Failure Response : HTTP_404_NOT_FOUND
{
"error": "Not Found",
"message": "404 Not Found: Product with id '1' could not be found.",
"status": 404
}
URL : http://127.0.0.1:8000/products/{int:product_id}
Method : DELETE
Auth required : No
Permissions required : None
Deletes a Product with id
Example:
Success Response : 204 NO CONTENT
URL : http://127.0.0.1:8000/products
Method : GET
Auth required : No
Permissions required : None
Lists all the Products
Example:
Success Response : HTTP_200_OK
[
{
"category": "dairy",
"created_date": "2023-03-07",
"deleted_date": null,
"desc": "This is more popular",
"discount": 1.0,
"id": 954,
"inventory": 5,
"modified_date": null,
"name": "Cheese",
"price": 0.5
}
]
The project contains the following:
.gitignore - this will ignore vagrant and other metadata files
.flaskenv - Environment variables to configure Flask
.gitattributes - File to gix Windows CRLF issues
.devcontainers/ - Folder with support for VSCode Remote Containers
dot-env-example - copy to .env to use environment variables
requirements.txt - list if Python libraries required by your code
config.py - configuration parameters
service/ - service python package
├── __init__.py - package initializer
├── models.py - module with business models
├── routes.py - module with service routes
└── common - common code package
├── error_handlers.py - HTTP error handling code
├── log_handlers.py - logging setup code
└── status.py - HTTP status constants
tests/ - test cases package
├── __init__.py - package initializer
├── test_models.py - test suite for business models
└── test_routes.py - test suite for service routes
Copyright (c) John Rofrano. All rights reserved.
Licensed under the Apache License. See LICENSE
This repository is part of the NYU masters class: CSCI-GA.2820-001 DevOps and Agile Methodologies created and taught by John Rofrano, Adjunct Instructor, NYU Courant Institute, Graduate Division, Computer Science, and NYU Stern School of Business.