
- Set up project structure with app modules - Configure SQLite database connection - Set up Alembic for database migrations - Implement Item model with CRUD operations - Create API endpoints for items management - Add health check endpoint - Add API documentation - Add comprehensive README
52 lines
1.2 KiB
Python
52 lines
1.2 KiB
Python
"""
|
|
CRUD operations for Item model.
|
|
"""
|
|
from typing import List, Optional
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.models.item import Item
|
|
from app.schemas.item import ItemCreate, ItemUpdate
|
|
from app.services.crud.base import CRUDBase
|
|
|
|
|
|
class CRUDItem(CRUDBase[Item, ItemCreate, ItemUpdate]):
|
|
"""CRUD operations for Item model."""
|
|
|
|
def get_by_title(self, db: Session, *, title: str) -> Optional[Item]:
|
|
"""
|
|
Get an item by title.
|
|
|
|
Args:
|
|
db: Database session
|
|
title: Item title
|
|
|
|
Returns:
|
|
Optional item
|
|
"""
|
|
return db.query(Item).filter(Item.title == title).first()
|
|
|
|
def get_multi_by_active(
|
|
self, db: Session, *, skip: int = 0, limit: int = 100
|
|
) -> List[Item]:
|
|
"""
|
|
Get multiple active items.
|
|
|
|
Args:
|
|
db: Database session
|
|
skip: Number of items to skip
|
|
limit: Maximum number of items to return
|
|
|
|
Returns:
|
|
List of active items
|
|
"""
|
|
return (
|
|
db.query(Item)
|
|
.filter(Item.is_active == True) # noqa: E712
|
|
.offset(skip)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
|
|
|
|
item = CRUDItem(Item) |