
- Set up project structure with FastAPI - Implement SQLAlchemy models for inventory items and categories - Create database connection with SQLite - Add CRUD operations for inventory management - Implement API endpoints for categories, items, and inventory transactions - Add health check endpoint - Set up Alembic for database migrations - Update README with documentation
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional, List, ForwardRef
|
|
|
|
|
|
# Shared properties
|
|
class CategoryBase(BaseModel):
|
|
name: str = Field(..., description="Category name", example="Electronics")
|
|
description: Optional[str] = Field(None, description="Category description", example="Electronic devices and accessories")
|
|
|
|
|
|
# Properties to receive via API on creation
|
|
class CategoryCreate(CategoryBase):
|
|
pass
|
|
|
|
|
|
# Properties to receive via API on update
|
|
class CategoryUpdate(BaseModel):
|
|
name: Optional[str] = Field(None, description="Category name", example="Electronics")
|
|
description: Optional[str] = Field(None, description="Category description", example="Electronic devices and accessories")
|
|
|
|
|
|
# Properties shared by models stored in DB
|
|
class CategoryInDBBase(CategoryBase):
|
|
id: int = Field(..., description="The unique identifier of the category")
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Properties to return to client
|
|
class Category(CategoryInDBBase):
|
|
pass
|
|
|
|
|
|
# Forward reference for Item
|
|
Item = ForwardRef("Item")
|
|
|
|
|
|
# Properties to return to client with relationships
|
|
class CategoryWithItems(CategoryInDBBase):
|
|
items: List[Item] = Field([], description="Items in this category")
|
|
|
|
|
|
# Import here to avoid circular import (moved down to fix linting)
|
|
from app.schemas.item import Item # noqa: E402
|
|
|
|
CategoryWithItems.model_rebuild() # Update forward references |