Spaces:
Runtime error
Runtime error
| from pydantic import BaseModel | |
| from fastapi import FastAPI | |
| from typing import List, Optional | |
| app = FastAPI() | |
| # 1. Define the blueprint for APIs | |
| class Customer(BaseModel): | |
| name: str | |
| email: str | |
| phone: Optional[str] = None | |
| address: Optional[str] = None | |
| customers_list = [] | |
| # Create | |
| def create_customer(customer: Customer): | |
| customers_list.append(customer) | |
| return customer | |
| # Read | |
| def get_customers(): | |
| return customers_list | |
| #Update | |
| def update_customer(customer_id: int, customer: Customer): | |
| customers_list[customer_id] = customer | |
| return customer | |
| #Delete | |
| def delete_customer(customer_id: int): | |
| customers_list.pop(customer_id) | |
| return {"message": "Customer deleted successfully"} | |