Public Access
feat: implement Phase 2 - Alembic migrations, Pydantic schemas, and real API endpoints
- Add initial Alembic migration with full PostgreSQL schema (enums, tables, indexes, constraints) - Add seed data migration with basic ingredients (70+) and family profile - Add Pydantic schemas for all models (FamilyProfile, Recipe, MealPlan, etc.) - Implement /api/profile endpoints (CRUD, family member management) - Implement /api/recipes endpoints (CRUD, ingredients, filtering) - Implement /api/meals endpoints (meal plans, voting, approval tokens) - Implement /api/pantry endpoints (CRUD for home pantry) - Implement /api/shopping-list endpoints (aggregation, print-ready HTML) - Implement /api/admin endpoints (scrape trigger, logs, stats) - Update ORIENTATION.md with Phase 2 progress
This commit is contained in:
@@ -1,20 +1,81 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
from app.database import get_db
|
||||
from app.models import HomePantry, Ingredient, FamilyProfile
|
||||
from app.schemas import HomePantryResponse, HomePantryCreate
|
||||
from uuid import UUID
|
||||
from typing import List
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/")
|
||||
def get_pantry(db: Session = Depends(get_db)):
|
||||
return {"message": "Pantry endpoint - not yet implemented"}
|
||||
@router.get("/", response_model=List[HomePantryResponse])
|
||||
def get_pantry_items(db: Session = Depends(get_db)):
|
||||
profile = db.query(FamilyProfile).first()
|
||||
if not profile:
|
||||
raise HTTPException(status_code=404, detail="Family profile not found")
|
||||
|
||||
items = db.query(HomePantry).filter(
|
||||
HomePantry.family_profile_id == profile.id
|
||||
).all()
|
||||
return items
|
||||
|
||||
|
||||
@router.post("/")
|
||||
def add_pantry_item(db: Session = Depends(get_db)):
|
||||
return {"message": "Add pantry item - not yet implemented"}
|
||||
@router.post("/", response_model=HomePantryResponse)
|
||||
def add_pantry_item(item: HomePantryCreate, db: Session = Depends(get_db)):
|
||||
profile = db.query(FamilyProfile).first()
|
||||
if not profile:
|
||||
raise HTTPException(status_code=404, detail="Family profile not found")
|
||||
|
||||
existing = db.query(HomePantry).filter(
|
||||
HomePantry.family_profile_id == profile.id,
|
||||
HomePantry.ingredient_id == item.ingredient_id
|
||||
).first()
|
||||
|
||||
if existing:
|
||||
existing.quantity = item.quantity
|
||||
existing.unit = item.unit
|
||||
existing.expires_at = item.expires_at
|
||||
db.commit()
|
||||
db.refresh(existing)
|
||||
return existing
|
||||
|
||||
db_item = HomePantry(
|
||||
family_profile_id=profile.id,
|
||||
ingredient_id=item.ingredient_id,
|
||||
quantity=item.quantity,
|
||||
unit=item.unit,
|
||||
expires_at=item.expires_at
|
||||
)
|
||||
|
||||
db.add(db_item)
|
||||
db.commit()
|
||||
db.refresh(db_item)
|
||||
return db_item
|
||||
|
||||
|
||||
@router.delete("/{item_id}")
|
||||
def remove_pantry_item(item_id: str, db: Session = Depends(get_db)):
|
||||
return {"message": f"Remove pantry item {item_id} - not yet implemented"}
|
||||
def remove_pantry_item(item_id: UUID, db: Session = Depends(get_db)):
|
||||
item = db.query(HomePantry).filter(HomePantry.id == item_id).first()
|
||||
if not item:
|
||||
raise HTTPException(status_code=404, detail="Pantry item not found")
|
||||
|
||||
db.delete(item)
|
||||
db.commit()
|
||||
return {"message": "Pantry item removed"}
|
||||
|
||||
|
||||
@router.put("/{item_id}", response_model=HomePantryResponse)
|
||||
def update_pantry_item(item_id: UUID, update: HomePantryCreate, db: Session = Depends(get_db)):
|
||||
item = db.query(HomePantry).filter(HomePantry.id == item_id).first()
|
||||
if not item:
|
||||
raise HTTPException(status_code=404, detail="Pantry item not found")
|
||||
|
||||
item.ingredient_id = update.ingredient_id
|
||||
item.quantity = update.quantity
|
||||
item.unit = update.unit
|
||||
item.expires_at = update.expires_at
|
||||
|
||||
db.commit()
|
||||
db.refresh(item)
|
||||
return item
|
||||
Reference in New Issue
Block a user