This is a FastAPI-based REST API for managing a food truck's menu, orders, and cart. It allows users to create and manage menu items, place orders with customizable options, and track order status while ensuring data validation and consistency.
- Menu Management: Add, update, retrieve, and delete menu items with customizable options
- Option Management: Add, update, retrieve, and delete options that can be added to menu items
- Cart Management: Add items to cart, customize with available options, update quantities, and clear cart
- Order Management: Create orders from cart, track order status, and process payments
- Validation: Ensures data consistency, validates order status transitions, and verifies option availability
- MongoDB Integration: Stores and retrieves data efficiently using PyMongo
- Testing: Comprehensive unit tests with pytest using mock collections
- FastAPI: Web framework for building APIs
- Pydantic: Data validation using Python type annotations
- MongoDB: Database (via PyMongo)
- pytest: Testing framework
- Python 3.8+: Core programming language
git clone <your-repo-url>
cd food-truck-apipython -m venv venv
source venv/bin/activate # On Unix/macOS
venv\Scripts\activate # On Windowspip install -r requirements.txtCreate a .env file in the root directory:
MONGO_URI=mongodb://localhost:27017/food_truckuvicorn app.main:app --reloadThe API will be available at http://localhost:8000
| Method | Endpoint | Description |
|---|---|---|
| GET | /menu/ |
List all menu items |
| POST | /menu/ |
Create a menu item |
| GET | /menu/{item_id} |
Get a specific menu item |
| PUT | /menu/{item_id} |
Update a menu item |
| DELETE | /menu/{item_id} |
Delete a menu item |
| Method | Endpoint | Description |
|---|---|---|
| GET | /options/ |
List all options |
| POST | /options/ |
Create an option |
| GET | /options/{option_id} |
Get a specific option |
| PUT | /options/{option_id} |
Update an option |
| DELETE | /options/{option_id} |
Delete an option |
| Method | Endpoint | Description |
|---|---|---|
| GET | /cart/ |
Get current cart |
| POST | /cart/items |
Add item to cart |
| PUT | /cart/items/{item_id} |
Update cart item |
| DELETE | /cart/items/{item_id} |
Remove item from cart |
| DELETE | /cart/ |
Clear cart |
| Method | Endpoint | Description |
|---|---|---|
| GET | /orders/ |
List all orders |
| POST | /orders/ |
Create order from cart |
| GET | /orders/{order_id} |
Get order by ID |
| PUT | /orders/{order_id}/status |
Update order status |
| POST | /orders/{order_id}/cancel |
Cancel order |
| POST | /orders/{order_id}/pay |
Process payment |
Orders follow this status progression:
pending- Initial state when order is createden préparation- After payment is processedprête- When order is ready for pickuplivrée- When order is deliveredannulée- When order is cancelled
Status Transition Rules:
- Orders can only be cancelled when in
pendingstate - Payment changes status from
pendingtoen préparation - Status must follow the sequence: pending → en préparation → prête → livrée
- Cancelled orders cannot be modified further
{
"id": "string",
"name": "string",
"description": "string",
"price": 0.00,
"category": "string",
"options": ["string"],
"available": true
}{
"id": "string",
"name": "string",
"price": 0.00
}{
"menu_item_id": "string",
"quantity": 1,
"selected_options": ["string"],
"special_instructions": "string",
"total_price": 0.00
}{
"id": "string",
"order_number": "FT-YYYY-NNNN",
"items": [CartItem],
"total_amount": 0.00,
"status": "pending",
"created_at": "datetime",
"updated_at": "datetime"
}- Item total = (base price + sum of option prices) × quantity
- Cart/Order total = sum of all item totals
- All calculations are performed server-side
- Prices are validated against current menu and option prices
Run the test suite:
pytest app/tests -vThe test suite includes:
- Unit tests for all routes
- Mock MongoDB collections for testing
- Status transition validation
- Price calculation verification
- Error handling scenarios
The API uses standard HTTP status codes:
- 200: Success
- 400: Bad Request (invalid data/status)
- 404: Not Found
- 500: Server Error
Validation errors include detailed messages about the specific issue.
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
MIT License