Automated Action b3827bf6b3 Add complete FastAPI delivery business backend
- Created customer, driver, and order models with SQLAlchemy
- Implemented CRUD API endpoints for all entities
- Set up SQLite database with Alembic migrations
- Added health check and base URL endpoints
- Configured CORS middleware for all origins
- Updated README with comprehensive documentation
2025-06-27 09:19:00 +00:00

85 lines
2.6 KiB
Markdown

# Delivery Business API
A simple FastAPI backend for managing a delivery business with customers, drivers, and orders.
## Features
- **Customer Management**: Create, read, update, and delete customers
- **Driver Management**: Manage drivers with availability and ratings
- **Order Management**: Handle delivery orders with status tracking
- **SQLite Database**: Lightweight database with Alembic migrations
- **Health Check**: Monitor service health at `/health`
- **Interactive API Docs**: Available at `/docs` and `/redoc`
## Setup and Installation
1. Install dependencies:
```bash
pip install -r requirements.txt
```
2. Run database migrations:
```bash
alembic upgrade head
```
3. Start the application:
```bash
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
```
The API will be available at `http://localhost:8000`
## API Endpoints
### Base
- `GET /` - Service information
- `GET /health` - Health check
- `GET /docs` - Interactive API documentation
- `GET /openapi.json` - OpenAPI schema
### Customers
- `POST /api/v1/customers` - Create customer
- `GET /api/v1/customers` - List customers
- `GET /api/v1/customers/{id}` - Get customer by ID
- `PUT /api/v1/customers/{id}` - Update customer
- `DELETE /api/v1/customers/{id}` - Delete customer
### Drivers
- `POST /api/v1/drivers` - Create driver
- `GET /api/v1/drivers` - List drivers (supports `available_only` filter)
- `GET /api/v1/drivers/{id}` - Get driver by ID
- `PUT /api/v1/drivers/{id}` - Update driver
- `DELETE /api/v1/drivers/{id}` - Delete driver
### Orders
- `POST /api/v1/orders` - Create order
- `GET /api/v1/orders` - List orders (supports `status` filter)
- `GET /api/v1/orders/{id}` - Get order by ID
- `PUT /api/v1/orders/{id}` - Update order
- `PATCH /api/v1/orders/{id}/assign-driver/{driver_id}` - Assign driver to order
- `PATCH /api/v1/orders/{id}/status` - Update order status
- `DELETE /api/v1/orders/{id}` - Delete order
## Database
The application uses SQLite database located at `/app/storage/db/db.sqlite`. Database migrations are managed using Alembic.
## Order Status Flow
Orders progress through the following statuses:
- `PENDING` - Order created, awaiting confirmation
- `CONFIRMED` - Order confirmed, driver assigned
- `PICKED_UP` - Package picked up by driver
- `IN_TRANSIT` - Package in transit
- `DELIVERED` - Package delivered successfully
- `CANCELLED` - Order cancelled
## Development
The application includes:
- CORS middleware configured to allow all origins
- Automatic API documentation generation
- Database relationship management
- Error handling and validation