REST API that implements the shopping cart behaviors. This project was developed using the stack Typescript + Node.js + PostgreSQL stack and applying the Clean Architecture concepts and SOLID principles.
- Save cart data
- Get cart data
- Add an item to cart
- Remove an item from cart
- Update the quantity of a cart item
- Clear cart items
- Apply a discount coupon to cart
In order to run the API in development environment, you must have at least the following tools installed: Git, Docker and Docker Compose.
# Clone repository
$ git clone [email protected]:viniciusmeneses/cart-api.git
# Go to project directory
$ cd cart-api
# Make a copy of envs configuration file
$ cp .env.sample .env
# Create database and start the server
$ docker-compose up -d
# Run database migrations
$ docker exec -t cart-api yarn migration:run
The API will be served on port 3000 by default and it can be accessed by URL http://localhost:3000.
Every endpoint and your returns were documented using Swagger and can be accessed by the path /docs
.
The following data will be inserted into the database when you run the migrations. It can be used when doing requests to endpoints that need an existing product or coupon.
// Products
{ id: "779d7f21-05b7-4a74-82e5-68b43c7d42d4", name: "T-shirt", price: 45.0, stock: 10 }
{ id: "a5d66c1a-b540-45ec-aab7-1e7dc932c38f", name: "Pants", price: 90.0, stock: 10 }
{ id: "c2f6dd0e-763e-4600-ad6f-0699be6ba5ae", name: "Sneakers", price: 199.99, stock: 3 }
{ id: "c98b3118-677d-4aec-9b06-d20f0015a5ac", name: "Sweatshirt", price: 149.99, stock: 5 }
{ id: "9450ea85-ab39-4d06-ae9f-8cd7f20ed4e6", name: "Cap", price: 20.0, stock: 4 }
// Discount coupons
{ id: "f99458a3-918e-4275-83bc-f62d5a891480", code: "GHW2O", percentage: 10.0 }
{ id: "695ba12a-7b9d-4c5d-8d70-649583590a34", code: "VEFJY", percentage: 5.0 }
{ id: "c4a9f80d-8ecc-4870-82f1-c436ac18581f", code: "D0JNN", percentage: 2.5 }