
- 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
34 lines
912 B
Python
34 lines
912 B
Python
from typing import List, Optional
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.db.crud_base import CRUDBase
|
|
from app.models.item import Category
|
|
from app.schemas.category import CategoryCreate, CategoryUpdate
|
|
|
|
|
|
class CRUDCategory(CRUDBase[Category, CategoryCreate, CategoryUpdate]):
|
|
"""
|
|
CRUD operations for Category
|
|
"""
|
|
def get_by_name(self, db: Session, *, name: str) -> Optional[Category]:
|
|
"""
|
|
Get a category by name
|
|
"""
|
|
return db.query(self.model).filter(self.model.name == name).first()
|
|
|
|
def get_multi_with_items(
|
|
self, db: Session, *, skip: int = 0, limit: int = 100
|
|
) -> List[Category]:
|
|
"""
|
|
Get multiple categories with their associated items
|
|
"""
|
|
return (
|
|
db.query(self.model)
|
|
.offset(skip)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
|
|
|
|
category = CRUDCategory(Category) |