Automated Action 4458f5320b Build e-commerce API with FastAPI and SQLite
- Implemented user authentication with JWT tokens
- Created product management endpoints
- Added shopping cart functionality
- Implemented order management system
- Setup database models with SQLAlchemy
- Created alembic migrations
- Added health check endpoint

generated with BackendIM... (backend.im)
2025-05-13 22:46:42 +00:00

89 lines
2.7 KiB
Markdown

# E-Commerce API
A RESTful API for e-commerce applications built with FastAPI and SQLite. This API provides endpoints for user authentication, product management, shopping cart functionality, and order processing.
## Features
- User authentication with JWT tokens
- Product catalog with filtering capabilities
- Shopping cart functionality
- Order management and processing
- Admin routes for managing products and orders
- Data persistence with SQLite
- Alembic migrations for database version control
## API Endpoints
### Authentication
- `POST /api/v1/auth/register` - Register a new user
- `POST /api/v1/auth/login` - Login and get access token
### Users
- `GET /api/v1/users/me` - Get current user information
- `PUT /api/v1/users/me` - Update current user information
- `GET /api/v1/users/{user_id}` - Get user by ID (admin or self only)
- `GET /api/v1/users/` - List all users (admin only)
- `DELETE /api/v1/users/{user_id}` - Delete a user (admin only)
### Products
- `GET /api/v1/products/` - List all active products with filtering options
- `POST /api/v1/products/` - Create a new product (admin only)
- `GET /api/v1/products/{product_id}` - Get product details
- `PUT /api/v1/products/{product_id}` - Update a product (admin only)
- `DELETE /api/v1/products/{product_id}` - Soft delete a product (admin only)
### Cart
- `GET /api/v1/cart/` - Get current user's cart items
- `POST /api/v1/cart/` - Add item to cart
- `PUT /api/v1/cart/{cart_item_id}` - Update cart item quantity
- `DELETE /api/v1/cart/{cart_item_id}` - Remove item from cart
- `DELETE /api/v1/cart/` - Clear cart
### Orders
- `GET /api/v1/orders/` - List user's orders (or all orders for admin)
- `POST /api/v1/orders/` - Create a new order from cart or specified items
- `GET /api/v1/orders/{order_id}` - Get order details with items
- `PUT /api/v1/orders/{order_id}/status` - Update order status (admin only)
- `DELETE /api/v1/orders/{order_id}` - Cancel a pending order
### Health Check
- `GET /health` - Check API health status
## Getting Started
### Prerequisites
- Python 3.8 or higher
### Installation
1. Clone the repository
```
git clone <repository-url>
```
2. Install dependencies
```
pip install -r requirements.txt
```
3. Initialize the database
```
alembic upgrade head
```
4. Run the server
```
uvicorn main:app --reload
```
## API Documentation
When the server is running, you can access the interactive API documentation at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
## Environment Variables
You can customize the following settings in the `app/core/config.py` file:
- `SECRET_KEY`: Secret key for JWT token generation
- `ACCESS_TOKEN_EXPIRE_MINUTES`: Token expiration time
- `BACKEND_CORS_ORIGINS`: CORS origin settings