Add subcription level filtering
This commit is contained in:
@@ -69,6 +69,30 @@ async def create_ingredient(
|
||||
)
|
||||
|
||||
|
||||
@router.get("/tenants/{tenant_id}/ingredients/count")
|
||||
async def count_ingredients(
|
||||
tenant_id: UUID = Path(...),
|
||||
current_user: dict = Depends(get_current_user_dep),
|
||||
db: AsyncSession = Depends(get_db)
|
||||
) -> dict:
|
||||
"""Get count of ingredients for a tenant"""
|
||||
|
||||
try:
|
||||
service = InventoryService()
|
||||
count = await service.count_ingredients_by_tenant(tenant_id)
|
||||
|
||||
return {
|
||||
"tenant_id": str(tenant_id),
|
||||
"ingredient_count": count
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Failed to count ingredients: {str(e)}"
|
||||
)
|
||||
|
||||
|
||||
@router.get("/tenants/{tenant_id}/ingredients/{ingredient_id}", response_model=IngredientResponse)
|
||||
async def get_ingredient(
|
||||
ingredient_id: UUID,
|
||||
|
||||
@@ -219,6 +219,30 @@ class InventoryService:
|
||||
logger.error("Failed to get ingredients", error=str(e), tenant_id=tenant_id)
|
||||
raise
|
||||
|
||||
async def count_ingredients_by_tenant(self, tenant_id: UUID) -> int:
|
||||
"""Count total number of active ingredients for a tenant"""
|
||||
try:
|
||||
async with get_db_transaction() as db:
|
||||
# Use SQLAlchemy count query for efficiency
|
||||
from sqlalchemy import select, func, and_
|
||||
|
||||
query = select(func.count(Ingredient.id)).where(
|
||||
and_(
|
||||
Ingredient.tenant_id == tenant_id,
|
||||
Ingredient.is_active == True
|
||||
)
|
||||
)
|
||||
|
||||
result = await db.execute(query)
|
||||
count = result.scalar() or 0
|
||||
|
||||
logger.info("Counted ingredients", tenant_id=tenant_id, count=count)
|
||||
return count
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Failed to count ingredients", error=str(e), tenant_id=tenant_id)
|
||||
raise
|
||||
|
||||
# ===== STOCK MANAGEMENT =====
|
||||
|
||||
async def add_stock(
|
||||
|
||||
Reference in New Issue
Block a user