Automated Action 0e00013b7f Implement product catalog API with CRUD operations
- Created FastAPI application with product catalog functionality
- Implemented CRUD operations for products
- Added SQLAlchemy models and Pydantic schemas
- Set up SQLite database with Alembic migrations
- Added health check endpoint
- Updated README with project documentation

generated with BackendIM... (backend.im)
2025-05-13 17:21:00 +00:00

38 lines
1.1 KiB
Python

from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field
class ProductBase(BaseModel):
name: str = Field(..., min_length=1, max_length=100, example="Smartphone XYZ")
description: Optional[str] = Field(None, example="Latest model with advanced features")
price: float = Field(..., gt=0, example=799.99)
sku: str = Field(..., min_length=3, max_length=50, example="SM-XYZ-2023")
stock: int = Field(0, ge=0, example=25)
category: Optional[str] = Field(None, example="Electronics")
class ProductCreate(ProductBase):
pass
class ProductUpdate(BaseModel):
name: Optional[str] = Field(None, min_length=1, max_length=100)
description: Optional[str] = None
price: Optional[float] = Field(None, gt=0)
sku: Optional[str] = Field(None, min_length=3, max_length=50)
stock: Optional[int] = Field(None, ge=0)
category: Optional[str] = None
class ProductInDB(ProductBase):
id: int
created_at: datetime
updated_at: datetime
class Config:
from_attributes = True
class Product(ProductInDB):
pass