🏗️ Código fonte completo: PostgreSQL, nutrição, receita, score labels, PWA fixes
This commit is contained in:
@@ -91,6 +91,9 @@ async def scan_product(req: ScanRequest, user: User = Depends(get_current_user),
|
||||
ingredients=analysis.get("ingredients", []),
|
||||
nutri_score=product_data.get("nutri_score"),
|
||||
nova_group=product_data.get("nova_group"),
|
||||
nutrition=analysis.get("nutrition"),
|
||||
nutrition_verdict=analysis.get("nutrition_verdict"),
|
||||
recipe=analysis.get("recipe"),
|
||||
source=source,
|
||||
)
|
||||
|
||||
@@ -104,3 +107,67 @@ async def get_history(user: User = Depends(get_current_user), db: AsyncSession =
|
||||
id=s.id, barcode=s.barcode, product_name=s.product_name,
|
||||
brand=s.brand, score=s.score, scanned_at=s.scanned_at
|
||||
) for s in scans]
|
||||
|
||||
@router.get("/history/{scan_id}")
|
||||
async def get_scan_detail(scan_id: int, user: User = Depends(get_current_user), db: AsyncSession = Depends(get_db)):
|
||||
result = await db.execute(
|
||||
select(Scan).where(Scan.id == scan_id, Scan.user_id == user.id)
|
||||
)
|
||||
scan = result.scalar_one_or_none()
|
||||
if not scan:
|
||||
raise HTTPException(status_code=404, detail="Scan não encontrado")
|
||||
|
||||
analysis = json.loads(scan.analysis_json or '{}')
|
||||
# Also get product info
|
||||
prod_result = await db.execute(select(Product).where(Product.barcode == scan.barcode))
|
||||
product = prod_result.scalar_one_or_none()
|
||||
|
||||
return {
|
||||
"id": scan.id,
|
||||
"barcode": scan.barcode,
|
||||
"product_name": scan.product_name,
|
||||
"brand": scan.brand,
|
||||
"score": scan.score,
|
||||
"summary": scan.summary,
|
||||
"scanned_at": scan.scanned_at.isoformat() if scan.scanned_at else None,
|
||||
"category": product.category if product else None,
|
||||
"image_url": product.image_url if product else None,
|
||||
"nutri_score": product.nutri_score if product else None,
|
||||
"nova_group": product.nova_group if product else None,
|
||||
"positives": analysis.get("positives", []),
|
||||
"negatives": analysis.get("negatives", []),
|
||||
"ingredients": analysis.get("ingredients", []),
|
||||
}
|
||||
|
||||
@router.get("/history/{scan_id}")
|
||||
async def get_scan_detail(scan_id: int, user: User = Depends(get_current_user), db: AsyncSession = Depends(get_db)):
|
||||
result = await db.execute(
|
||||
select(Scan).where(Scan.id == scan_id, Scan.user_id == user.id)
|
||||
)
|
||||
scan = result.scalar_one_or_none()
|
||||
if not scan:
|
||||
raise HTTPException(status_code=404, detail="Scan não encontrado")
|
||||
|
||||
analysis = json.loads(scan.analysis_json or '{}')
|
||||
prod_result = await db.execute(select(Product).where(Product.barcode == scan.barcode))
|
||||
product = prod_result.scalar_one_or_none()
|
||||
|
||||
return {
|
||||
"id": scan.id,
|
||||
"barcode": scan.barcode,
|
||||
"product_name": scan.product_name,
|
||||
"brand": scan.brand,
|
||||
"score": scan.score,
|
||||
"summary": scan.summary,
|
||||
"scanned_at": scan.scanned_at.isoformat() if scan.scanned_at else None,
|
||||
"category": product.category if product else None,
|
||||
"image_url": product.image_url if product else None,
|
||||
"nutri_score": product.nutri_score if product else None,
|
||||
"nova_group": product.nova_group if product else None,
|
||||
"positives": analysis.get("positives", []),
|
||||
"negatives": analysis.get("negatives", []),
|
||||
"ingredients": analysis.get("ingredients", []),
|
||||
"nutrition": analysis.get("nutrition", {}),
|
||||
"nutrition_verdict": analysis.get("nutrition_verdict", ""),
|
||||
"recipe": analysis.get("recipe"),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user