Public Access
feat: allow adding pantry items by text input with auto-ingredient creation
- backend: expose POST /api/ingredients on public router so frontend can create ingredients without admin token - frontend/api: point listIngredients and createIngredient to /api/ingredients - frontend/pantry: replace ingredient dropdown with searchable text input + fuzzy matching + auto-create
This commit is contained in:
@@ -55,6 +55,26 @@ def get_ingredient(ingredient_id: UUID, db: Session = Depends(get_db)) -> Ingred
|
||||
return row
|
||||
|
||||
|
||||
@public_router.post("", response_model=IngredientRead, status_code=status.HTTP_201_CREATED)
|
||||
def create_ingredient_public(payload: IngredientCreate, db: Session = Depends(get_db)) -> Ingredient:
|
||||
row = Ingredient(
|
||||
name=payload.name,
|
||||
name_lower=payload.name.lower(),
|
||||
aliases=payload.aliases,
|
||||
aisle=payload.aisle,
|
||||
unit=payload.unit,
|
||||
typical_price=payload.typical_price,
|
||||
)
|
||||
db.add(row)
|
||||
try:
|
||||
db.commit()
|
||||
except IntegrityError:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=409, detail="ingredient name already exists")
|
||||
db.refresh(row)
|
||||
return row
|
||||
|
||||
|
||||
@admin_router.post("", response_model=IngredientRead, status_code=status.HTTP_201_CREATED)
|
||||
def create_ingredient(payload: IngredientCreate, db: Session = Depends(get_db)) -> Ingredient:
|
||||
row = Ingredient(
|
||||
|
||||
Reference in New Issue
Block a user