Automated Action a28e115e4f Implement simple cart system with FastAPI and SQLite
- Set up project structure with FastAPI and SQLite
- Create models for products and cart items
- Implement schemas for API request/response validation
- Add database migrations with Alembic
- Create service layer for business logic
- Implement API endpoints for cart operations
- Add health endpoint for monitoring
- Update documentation
- Fix linting issues
2025-05-18 23:36:40 +00:00

111 lines
2.3 KiB
Markdown

# Simple Cart System
A simple shopping cart system API built with FastAPI and SQLite.
## Features
- Product management (CRUD operations)
- Shopping cart functionality
- User-specific carts
- Stock management
## Getting Started
### Prerequisites
- Python 3.8 or higher
- pip (Python package manager)
### Installation
1. Clone the repository:
```bash
git clone <repository-url>
cd simplecartsystem
```
2. Install the dependencies:
```bash
pip install -r requirements.txt
```
3. Run database migrations:
```bash
alembic upgrade head
```
4. Start the application:
```bash
uvicorn main:app --reload
```
The API will be available at http://localhost:8000.
## API Documentation
Interactive API documentation is available at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
## API Endpoints
### Health Check
- `GET /api/v1/health` - Check API and database health
### Products
- `GET /api/v1/products` - List all products (with pagination)
- `GET /api/v1/products/{product_id}` - Get a specific product
- `POST /api/v1/products` - Create a new product
- `PUT /api/v1/products/{product_id}` - Update a product
- `DELETE /api/v1/products/{product_id}` - Delete a product
### Cart
- `GET /api/v1/cart` - View current cart
- `POST /api/v1/cart/items` - Add item to cart
- `PUT /api/v1/cart/items/{item_id}` - Update cart item quantity
- `DELETE /api/v1/cart/items/{item_id}` - Remove item from cart
- `DELETE /api/v1/cart` - Clear cart
## Cart Usage Example
### Add Product to Cart
```bash
curl -X POST "http://localhost:8000/api/v1/cart/items" \
-H "Content-Type: application/json" \
-H "user-id: user123" \
-d '{
"product_id": 1,
"quantity": 2
}'
```
### View Cart
```bash
curl -X GET "http://localhost:8000/api/v1/cart" \
-H "user-id: user123"
```
## Database Schema
The system uses SQLite with the following main tables:
- `products`: Stores product information
- `carts`: Stores user cart information
- `cart_items`: Stores items in user carts
## Technology Stack
- [FastAPI](https://fastapi.tiangolo.com/) - Web framework
- [SQLAlchemy](https://www.sqlalchemy.org/) - ORM
- [Alembic](https://alembic.sqlalchemy.org/) - Database migrations
- [Pydantic](https://pydantic-docs.helpmanual.io/) - Data validation
- [SQLite](https://www.sqlite.org/) - Database