
- Created FastAPI application with SQLite database - Implemented models for inventory items, categories, suppliers, and transactions - Added authentication system with JWT tokens - Implemented CRUD operations for all models - Set up Alembic for database migrations - Added comprehensive API documentation - Configured Ruff for code linting
68 lines
2.3 KiB
Python
68 lines
2.3 KiB
Python
from typing import Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class ItemBase(BaseModel):
|
|
"""
|
|
Base item schema with common attributes.
|
|
"""
|
|
name: str = Field(..., description="Item name")
|
|
description: Optional[str] = Field(None, description="Item description")
|
|
sku: Optional[str] = Field(None, description="Stock Keeping Unit")
|
|
barcode: Optional[str] = Field(None, description="Barcode/UPC")
|
|
quantity: int = Field(0, description="Current stock quantity", ge=0)
|
|
unit_price: float = Field(..., description="Unit price", gt=0)
|
|
reorder_level: int = Field(10, description="Quantity at which to reorder", ge=0)
|
|
category_id: Optional[int] = Field(None, description="ID of the category")
|
|
supplier_id: Optional[int] = Field(None, description="ID of the supplier")
|
|
|
|
|
|
class ItemCreate(ItemBase):
|
|
"""
|
|
Schema for item creation.
|
|
"""
|
|
pass
|
|
|
|
|
|
class ItemUpdate(BaseModel):
|
|
"""
|
|
Schema for updating item information.
|
|
"""
|
|
name: Optional[str] = Field(None, description="Item name")
|
|
description: Optional[str] = Field(None, description="Item description")
|
|
sku: Optional[str] = Field(None, description="Stock Keeping Unit")
|
|
barcode: Optional[str] = Field(None, description="Barcode/UPC")
|
|
quantity: Optional[int] = Field(None, description="Current stock quantity", ge=0)
|
|
unit_price: Optional[float] = Field(None, description="Unit price", gt=0)
|
|
reorder_level: Optional[int] = Field(None, description="Quantity at which to reorder", ge=0)
|
|
category_id: Optional[int] = Field(None, description="ID of the category")
|
|
supplier_id: Optional[int] = Field(None, description="ID of the supplier")
|
|
|
|
|
|
class ItemInDBBase(ItemBase):
|
|
"""
|
|
Base schema for items from the database.
|
|
"""
|
|
id: int = Field(..., description="Item ID")
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class Item(ItemInDBBase):
|
|
"""
|
|
Schema for item information returned to clients.
|
|
"""
|
|
pass
|
|
|
|
|
|
class ItemWithRelations(ItemInDBBase):
|
|
"""
|
|
Schema for item with related entities.
|
|
"""
|
|
from app.schemas.category import Category
|
|
from app.schemas.supplier import Supplier
|
|
|
|
category: Optional[Category] = Field(None, description="Item category")
|
|
supplier: Optional[Supplier] = Field(None, description="Item supplier") |