
- Setup FastAPI project structure - Add database models for calculations - Create API endpoints for basic math operations - Add health endpoint - Configure SQLite and Alembic for database management - Update README with usage instructions generated with BackendIM... (backend.im)
19 lines
620 B
Python
19 lines
620 B
Python
from datetime import datetime
|
|
from typing import Optional
|
|
from pydantic import BaseModel, Field
|
|
|
|
class CalculationBase(BaseModel):
|
|
operation: str = Field(..., description="Mathematical operation: add, subtract, multiply, divide, or square_root")
|
|
first_number: float = Field(..., description="First operand")
|
|
second_number: Optional[float] = Field(None, description="Second operand (not required for square_root)")
|
|
|
|
class CalculationCreate(CalculationBase):
|
|
pass
|
|
|
|
class CalculationResponse(CalculationBase):
|
|
id: int
|
|
result: float
|
|
created_at: datetime
|
|
|
|
class Config:
|
|
orm_mode = True |