Skip to content

STEP 5- Implement upload.py — wire OCR pipeline and write results to pantry #12

@staticvoidmainmaui

Description

@staticvoidmainmaui

Body:

backend/app/routers/upload.py needs to implement POST /upload/receipt. This is the endpoint that ties the entire Vision pipeline together (Steps 2–4) and writes the results into the user's pantry.

Endpoint: POST /upload/receipt

  • Auth: Depends(verify_firebase_token) → uid
  • Body: multipart/form-data with an image file

Data flow to implement:
image file upload
→ await file.read() → image_bytes
→ validate: len(image_bytes) ≤ 10 MB (raise 413 if exceeded)
→ ocr_service.extract_text(image_bytes) → raw_text
→ receipt_parser.parse(raw_text) → parsed_names
→ [normalizer.normalize(n) for n in parsed_names] → normalized_names
→ for each name: db.collection("users").document(uid).collection("pantry").document().set(...)
→ return ReceiptUploadResponse(raw_text=raw_text, parsed_items=[...])

Depends on:

  • ocr_service.py, receipt_parser.py, normalizer.py (Steps 2–4, already implemented)
  • Firebase Admin + db initialized (Step 1)
  • pantry_service for the Firestore write (or write directly to users/{uid}/pantry/)

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions