A cart service, because what is a shop without a cart to put stuff in?
The Cart service is part of the ACME Fitness Shop. The goal of this specific service is to keep track of carts and items in the different carts.
There are different dependencies based on whether you want to run a built container, or build a new one.
Use this command to pull the latest tagged version of the shipping service:
docker pull gcr.io/vmwarecloudadvocacy/acmeshop-cart:stable
To build a docker container, run docker build . -t vmwarecloudadvocacy/acmeshop-cart:<tag>
.
The images are tagged with:
<Major>.<Minor>.<Bug>
, for example1.1.0
stable
: denotes the currently recommended image appropriate for most situationslatest
: denotes the most recently pushed image. It may not be appropriate for all use cases
To build the app as a stand-alone executable, run pip install -r requirements.txt
to install the Python libraries and run python3 cart.py
after.
The cart service, either running inside a Docker container or as a stand-alone app, relies on the below environment variables:
- REDIS_HOST: The hostname or IP address to connect to the Redis server (defaults to
localhost
) - REDIS_PORT: The port to connect to the Redis server (defaults to
6379
) - REDIS_PASSWORD: The password to connect to Redis (defaults to
blank
) - CART_PORT: The port number the cart service will listen to requests (defaults to
5000
)
The Docker image is based on the Bitnami Python container. Use this commands to run the latest stable version of the payment service with all available parameters:
# Run the Redis container
docker run -p 6379:6379 bitnami/redis:latest
# Run the cart service
docker run --rm -it -e REDIS_HOST=localhost -e REDIS_PORT=6379 -e REDIS_PASSWORD=myAwesomePassword -e CART_PORT=5000 -p 5000:5000 gcr.io/vmwarecloudadvocacy/acmeshop-cart:stable
Get total amount in users cart
curl --request GET \
--url http://localhost:5000/cart/total/dan
{
"carttotal": 804.5,
"userid": "dan"
}
Update an item in the cart of a user
curl --request POST \
--url http://localhost:5000/cart/item/modify/dan \
--header 'content-type: application/json' \
--data '{"itemid":"sfsdsda3343", "quantity":2}'
To modify the item in a cart, the input needs to contain an itemid
and the new quantity
{"itemid":"sfsdsda3343", "quantity":2}
A successful update will return the userid
{
"userid": "dan"
}
Modify the contents of a cart
curl --request POST \
--url http://localhost:5000/cart/modify/dan \
--header 'content-type: application/json' \
--data '{
"cart": [
{
"description": "fitband for any age - even babies",
"itemid": "sdfsdfsfs",
"name": "fitband",
"price": 4.5,
"quantity": 1
},
{
"description": "the most awesome redpants in the world",
"itemid": "sfsdsda3343",
"name": "redpant",
"price": 400,
"quantity": 1
}
],
"userid": "dan"
}'
To replace the entire cart, or create a new cart for a user, send a cart object
{
"cart": [
{
"description": "fitband for any age - even babies",
"itemid": "sdfsdfsfs",
"name": "fitband",
"price": 4.5,
"quantity": 1
}
],
"userid": "dan"
}
A successful update will return the userid
{
"userid": "dan"
}
Add item to cart
curl --request POST \
--url http://localhost:5000/cart/item/add/shri \
--header 'content-type: application/json' \
--data '{"itemid":"xyz", "quantity":3}'
To add the item in a cart, the input needs to contain an itemid
and the quantity
{"itemid":"xyz", "quantity":3}
A successful update will return the userid
{
"userid": "shri"
}
Get the total number of items in a cart
curl --request GET \
--url http://localhost:5000/cart/items/total/shri
{
"cartitemtotal": 5.0,
"userid": "shri"
}
Clear all items from the cart
curl --request GET \
--url http://localhost:5000/cart/clear/dan
<no payload returned>
Get all items in a cart
curl --request GET \
--url http://localhost:5000/cart/items/dan
{
"cart": [
{
"description": "fitband for any age - even babies",
"itemid": "sdfsdfsfs",
"name": "fitband",
"price": 4.5,
"quantity": 1
},
{
"description": "the most awesome redpants in the world",
"itemid": "sfsdsda3343",
"name": "redpant",
"price": 400,
"quantity": 1
}
],
"userid": "dan"
}
Get all the carts
curl --request GET \
--url http://localhost:5000/cart/all
{
"all carts": [
{
"cart": [
{
"description": "fitband for any age - even babies",
"itemid": "sdfsdfsfs",
"name": "fitband",
"price": 4.5,
"quantity": 1
},
{
"description": "the most awesome redpants in the world",
"itemid": "sfsdsda3343",
"name": "redpant",
"price": 400,
"quantity": 1
}
],
"id": "shri"
}
]
}
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
See the LICENSE file in the repository